       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
>
> 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:=
FullForm[Times[#,m]&]
Out//FullForm=
Function[Times[Slot, m]]

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

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

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

In:=
mult= With[{m=3},Times[#,m]&]
Out=
#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