MathGroup Archive 1995

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

Search the Archive

Re: [m1220] Equating a variable and its value

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg1267] Re: [m1220] Equating a variable and its value
  • From: Allan Hayes <hay at haystack.demon.co.uk>
  • Date: Wed, 31 May 1995 02:15:37 -0400

Jan Snellman <jans at matematik.su.se>
[m1220] Equating a variable and its value
writes

> 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?

Jan,

First notice
In[2]:=
FullForm[Times[#,m]&]
Out[2]//FullForm=
Function[Times[Slot[1], m]]

Now here is your example step by step
In[3]:=
	mult=Times[#,m]& (*Function is HoldAll so m is mot evaluated*)
Out[3]=
	#1 m &
In[4]:=
	Clear[m](*Clear is HoldAll;m is cleared, not 3;
	          m now has no value*)
In[5]:=
	mult[10] (*10 replaces # in Times[#,m]& and
           	   then Function is stripped off
           	   but now m has no value*)
Out[5]=
	10 m

To get what you want;
In[6]:=
	m=3
Out[6]=
	3
In[7]:=
	mult= Evaluate[Times[#,m]]&  (*override HoldAll, force   		
					evaluation*)
Out[7]=
	3 #1 &
In[8]:=
	Clear[m]
In[9]:=
	mult[10]
Out[9]=
	30

If you want to specifically limit evaluation to m  then you can use

In[10]:=
	mult= With[{m=3},Times[#,m]&]
Out[10]=
	#1 3 &
	
The distinction between an expression and its value is crucial in  
any symbolic system, in mathematics and in ordinary language.

Allan Hayes
hay at haystack.demon.co.uk



  • Prev by Date: Re: Numerous Functional Forms
  • Next by Date: Re: Reading Bytes: unexpected EOF ???
  • Previous by thread: Re: [m1220] Equating a variable and its value
  • Next by thread: COMPILATION OF ROUTINES USING LISTS OF REALS