Re: Equating a variable and its value
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg1236] Re: Equating a variable and its value
- From: fateman at peoplesparc.cs.berkeley.edu (Richard J Fateman)
- Date: Fri, 26 May 1995 04:50:01 -0400
- Organization: University of California, Berkeley
In article <3puhq7$m8n at news0.cybernetics.net>, Jan Snellman <jans at matematik.su.se> 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? ........... Sorry, there are good reasons in symbolic programming systems to make the distinction. And you are probably on the wrong side of the argument from where you want to be, if you are unhappy with the above result. What you seem to want is a lexically scoped language, which Mathematica IS NOT. Consider by comparison the Scheme procedure defined by this similar line... (let ((m 3)) (define mult (x)(* x m))) Then you can change the binding of m globally by (define m 4000) ;; or anything.. (mult 10) ===> 30 as YOU would expect. Is there a way of saying this in Mathematica? Well sort of. This was added to Mathematica when some pedants (among them, me) showed that "Block" was pretty much useless. WRI added Module: h=Module[{m=3},Function[{x},x*m]] now h[4] is 12 regardless of what value is given to m. However, if you dare to give a value to m$1, say m$1=5, then h[4] will be 20. A result that a pedant would object to. (Your number may vary from m$1 to some other m$...). By the way, there are many contexts in which the distinction between name and value matter: witness the Abbott and Costello dialog "Who's on First". RJF -- Richard J. Fateman fateman at cs.berkeley.edu 510 642-1879