# Can't understand one paragraph in Power Programming with Mathematica

In the chapter 7 of the Power Programming with Mathematica, there is a paragraph discussing the behavior of Set- functions: (page 205. (pdf version p. 224))

However, I can't get the author's meaning. It may due to the material itself, or due to the reason that I'm not native speaker in English. I totally don't get the red line part, as well unable to see how the word "because" is used here, what is the logical inference here?

Also, I can't get what author mean in the blue part in next page. Need help.

Update question: If it would not evaluate Parts of the left hand side, then except for the reason that assigning to variables in a List was no longer possible (e.g. {a,b,c}={1,2,3}), is there other decided reason or critical situation that something would not work well, so we would really appreciate if such partial evaluation is enabled?

• About update, if I understand your question well it seems that memoization/caching could be tricky. e.g. temp=1; f[temp]=2; temp=3;f[temp]=4]. – Kuba Mar 22 '18 at 7:29

He is simply saying that the first argument of Set is not evaluated before Set creates the definition.

However, the sub-parts of the first argument are all evaluated, including the head(i.e. part 0).

Thus in

f[x] = y


f[x] is not evaluated in the sense that any previous definition similar to f[z_] := z^2 will be ignored. However, f is evaluated and x is evaluated. Furthermore, any Hold-attributes f might have will prevent evaluation as usual.

Through examples:

Given these definitions,

ClearAll[f, x, foo]

f[a_] := foo

x = 1;


what new definitions will the following command create?

f[x] = y
(* y *)


It will not assign to foo because f[x] won't evaluate. It will also not assign to f[x] because x will evaluate. It will instead assign to f[1].

?f

Globalf

f[1]=y

f[a_]:=foo


However, if f has the HoldAll (or similar) attributes, Set will honour this before evaluating parts of its left-hand-side.

ClearAll[f, x, foo]
SetAttributes[f, HoldAll];

f[a_] := foo

x = 1;

f[x] = y
(* y *)

?f

Globalf

Attributes[f]={HoldAll}

f[x]=y

f[a_]:=foo

• (Assuming the following discussion is without Hold- attributes.) So if the lhs of =(Set) is atomic symbol, then it is held. If the lhs of Set is in contrast normal equation, namely of the form h[expr1,expr2,...], then h is evaluated, expr1, expr2, ... are also evaluated? But being that said, if there is a direct global rule defined beforehand that can match h[expr1,expr2,...], then the kernel would pretend not knowing it. – Eric Mar 19 '18 at 14:39
• Is my understanding correct? – Eric Mar 22 '18 at 7:11

If Set would not have the HoldFirst attribute, it would lead to undesired behavior if variables on the left hand side have already values assigned to them. Here is an emulation of that:

set[a_, b_] := Set[a, b]
ClearAll[a, b, c]
set[a, 1]
set[a, 2]
a


1

Set::setraw: Cannot assign to raw object 1.

2

1

If it would not evaluate Parts of the left hand side, then assigning to variables in a List was not possible (this can be considered as syntax sugar). Here I emulate what would happen if Set would handle List on its left hand side like any other head:

ClearAll[a, b, c, list];
set[list[a, b, c], list[1, 2, 3]];
{a, b, c}
list[a, b, c]


{a, b, c}

list[1, 2, 3]

• Is there a typo of the result on the very last line list[a, b, c]? My 10.4 version gave me the answer list[1,2,3]. – Eric Mar 19 '18 at 14:56
• @Eric Jepp. Fixed. – Henrik Schumacher Mar 19 '18 at 15:01
• If it would not evaluate Parts of the left hand side, then except for the reason that assigning to variables in a List was no longer possible (e.g. {a,b,c}={1,2,3}), is there other decided reason or critical situation that something would not work well, so we would really appreciate if such partial evaluation is enabled? – Eric Mar 22 '18 at 4:20
• I would sey no, there is no other reason, at least no one that comes to my mind. Of course, I don't know for sure. – Henrik Schumacher Mar 22 '18 at 7:03