Re: Pattern matching at bottom depth
- To: mathgroup at smc.vnet.net
- Subject: [mg63342] Re: [mg63336] Pattern matching at bottom depth
- From: "David Park" <djmp at earthlink.net>
- Date: Sat, 24 Dec 2005 16:02:52 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Luc,
You could use Map with a negative level specification.
lst1 = {{0, 0, 0}, {1, 2, 3}};
lst2 = {{{0, 0, 0}, {1, 1, 1}}, {{1, 1, 1}, {2, 2, 2}, {3, 4, 3}}};
Map[transform, lst1, {-2}]
{transform[{0, 0, 0}], transform[{1, 2, 3}]}
Map[transform, lst2, {-2}]
{{transform[{0, 0, 0}], transform[{1, 1, 1}]}, {transform[{1, 1, 1}],
transform[{2, 2, 2}], transform[{3, 4, 3}]}}
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
From: Barthelet, Luc [mailto:lucb at ea.com]
To: mathgroup at smc.vnet.net
I have a function Foo (attribute hold) that will take 3D Points as
arguments either in a list or a list of lists.
So I can call:
Foo[{{0,0,0},{1,2,3}}]
Or
Foo[{{{0,0,0},{1,1,1}},{{1,1,1},{2,2,2},{3,4,3}}}]
Now, I would like to pattern match the triplets, so that I can run a
transformation (transform[u]) on them before releasing the hold on Foo.
Currently I do it with 2 rules and the conditional use of dimensions.
Foo [u_ /; Length[Dimensions[u]] == 2] :> Foo [transform /@ u],
Foo [u_ /; Length[Dimensions[u]] == 3] :> Foo [Map[transform, u,{2}]]
Is there a better way to do this?
Thanks
Luc