MathGroup Archive 1995

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

Search the Archive

Re: Equating a variable and its value


In article <3puhq7$m8n at news0.cybernetics.net>,
   jans at matematik.su.se (Jan Snellman) wrote:
->
->Hello folks.
->
->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?
->
->Regards,
->Jan Snellman	jans at matematik.su.se
->
The problem is that Function (which you are invoking with the ampersand 
suffix) has attribute HoldAll:  it holds all its arguments unevaluated.  If 
you wrap the function (excluding the ampersand) in Evaluate[], you get what 
you wanted:

  m=3; mult=Evaluate[Times[#,m]]&; Clear[m]; mult[10]

produces result 30.

Paul

**************************************************************************
* Paul A. Rubin                                  Phone: (517) 432-3509   *
* Department of Management                       Fax:   (517) 432-1111   *
* Eli Broad Graduate School of Management        Net:   RUBIN at MSU.EDU    *
* Michigan State University                                              *
* East Lansing, MI  48824-1122  (USA)                                    *
**************************************************************************
Mathematicians are like Frenchmen:  whenever you say something to them,
they translate it into their own language, and at once it is something
entirely different.                                    J. W. v. GOETHE


  • Prev by Date: Re: Equating a variable and its value
  • Next by Date: strings into lists
  • Previous by thread: Re: Equating a variable and its value
  • Next by thread: INTERACTIVE USE OF MATHEMATICA