MathGroup Archive 1995

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

Search the Archive

Summary: equating a variable with its value


Hello again, folks!
A few days ago, I presented my problems with the pure function
multiplication by m :

>Study this codelet:
>
>m=3; mult=Times[#,m]&; Clear[m]; mult[10]
>
>To my dismay, I get 10 m, not 30.
>How can i convince Mathematica that only pedants make the distinction
>between a variable and its value?

The response has been overwhelming! Thank you all!
I feel it is my duty to summarize the many and instructing answers I
received. 

1. mult = Function[x,x #]& [m]

2. mult = With[{m = m}, Times[#, m]& ]

3. mult=Module[{n=m},Function[{x},x*n]]

4. mult=Evaluate[Times[#,m]]&

5. ClearAttributes[Function,{Protected,HoldAll}]; mult=Times[#,m]&

6. SetMult[v_] := mult=Times[v,#]&; SetMult[m]

7. mult = Times[#, m]& /. Literal[m] -> m


--
Jan Snellman         : "Whenever you find that you are on the side of the 
jans at matematik.su.se : majority, it is time to reform."  M T


  • Prev by Date: COMPILATION OF ROUTINES USING LISTS OF REALS
  • Next by Date: Re: Problem with Solve and O[x]
  • Previous by thread: COMPILATION OF ROUTINES USING LISTS OF REALS
  • Next by thread: Strange behavior of Polygon...