MathGroup Archive 1995

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

Search the Archive

Summary: renaming in Function[] and Module[]


In reply to Paul E Howland's message "[mg523] Confused about 
contexts...", Robby Villegas explained in message "[mg570] ..." on the 
issue of renaming by Function and Module. It was GREAT. Thanks Robby. I 
myself run into this exact problem 2 weeks ago.

The way I solved the problem is by using   Function[ z/. x-># ].
Here is a summary.

Problem:
 we expect the definition
   test[a_] := Module[{z}, z=Sin[x/a]; Function[x,z]]
 to behave like this
 test[m] should return Function[x,Sin[x/a]], but instead it returns
 Function[x$, z$10]. What to do?

Solutions:

test1[a_] := Module[{z}, z = Sin[x/a]; Function @@ {x, z}]
test2[a_] := Module[{z}, z = Sin[x/a]; Function[ z/. x->#] ]
test3[a_] := Module[{z}, z=Sin[x/a]; (Function[Evaluate@z]/.x->#) ]

the following wouldn't work:

test4[a_] := Module[{z}, z=Sin[x/a]; Function[x,z]]
test5[a_] := Module[{z}, z=Sin[x/a]; Function[x,Evaluate@z]]
test6[a_] := Module[{z}, z=Sin[x/a]; Evaluate@Function[x, z] ]
test7[a_] := Module[{z}, z=Sin[x/a]; (Function[z]/.x->#) ]
test8[a_] := Module[{z}, z=Sin[x/a]; Evaluate@(Function[z]/.x->#) ]


 Xah Lee      a Stud at some higher learning place.
  Quote of the day:
   Soap opera makes some people shed tears, onion cause others.
   Some shed tears because of war, some for joy.
   I shed tears for nothing but Mathematica.   --Hearty Mathematician




  • Prev by Date: Re: Re (-1)^(3/4) -> (-1+I)/Sqrt[2] ?
  • Next by Date: A Fancy Animation
  • Previous by thread: Re: Re (-1)^(3/4) -> (-1+I)/Sqrt[2] ?
  • Next by thread: A Fancy Animation