Summary: renaming in Function[] and Module[]
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg592] Summary: renaming in Function[] and Module[]
- From: Xah Y Lee <xyl10060 at fhda.edu>
- Date: Thu, 23 Mar 1995 01:28:41 -0800 (PST)
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