Group Abstract Group Abstract

Message Boards Message Boards

0
|
9K Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Understand the standard evaluation chain on global variables?

Posted 8 years ago

I don't understand the behaviour of the following:

test0[x_, y_] := Module[
   {},
   a = 2*x;
   Return[y]
   ];

test1[] := Module[
   {},
   a
   ];

Now I run this little programms:

In[168]:= Remove["a"]
test0[1, test1[]]
test0[2, test1[]]
test0[3, test1[]]

Out[169]= 2

Out[170]= 2

Out[171]= 4

If "a" ist not defined, "a" will be evaluated in bevor calling test1[], but if "a" has already a value then "a" is evaluated after calling test1[]. How can I force that "a" ist always evaluated before?

POSTED BY: Juerg Baertsch
2 Replies
Posted 8 years ago

Thank you very much, Unevaluated[] is exactly what I was lookin for.

That the function in the argument ist evaluatet first, was logical for me. I was only confused, because I thought that then the first output must be the symbol "a" and not 2. My wrong conclusion was, that in this case (when a has no value) the argument is evaluated later. But I see now, that this is wrong. Its evaluated to the symbol "a" and so the "a=2*x" works.

Thanks again for solving my confusion ;)

POSTED BY: Juerg Baertsch
POSTED BY: Patrick Scheibe
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard