Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Pattern matching at bottom depth

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63345] Re: [mg63336] Pattern matching at bottom depth
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sat, 24 Dec 2005 16:02:55 -0500 (EST)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

t = {x_?AtomQ, y_, z_} :> transform[{x, y, z}];

Foo[{{x1,y1,z1},{x2,y2,z2}}]/.t

Foo({transform({x1,y1,z1}),transform({x2,y2,z2})})

Foo[{{{0,0,0},{1,1,1}},{{1,1,1},{2,2,2},{3,4,3}}}]/.t

Foo({{transform({0,0,0}),transform({1,1,1})},{transform({1,1,1}),transform({
          2,2,2}),transform({3,4,3})}})


Bob Hanlon

> 
> From: "Barthelet, Luc" <lucb at ea.com>
To: mathgroup at smc.vnet.net
> Date: 2005/12/24 Sat AM 07:19:02 EST
> Subject: [mg63345] [mg63336] Pattern matching at bottom depth
> 
> 
> 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
> 
> 
> 
> 


  • Prev by Date: Re: Pattern matching at bottom depth
  • Next by Date: Re: ExpToTrig with Real Numbers
  • Previous by thread: Re: Pattern matching at bottom depth
  • Next by thread: Questions regarding MatrixExp, and its usage