"logo.gif"  
Main
Read Online
Download PDF
Additional resources
Revision history
Known typos/bugs
Report a bug
License terms
About the author
"node97_1.gif" "node97_2.gif" "node97_3.gif"

2.4.1    Immediate and delayed assignments: Set and SetDelayed

There are two assignment commands in Mathematica: immediate and delayed assignment.

The immediate assignment is performed with the equal sign (=), say x = y, which means "assign to x the value that y has right now". This command has a literal equivalent Set: we  could equivalently write Set[x,y]. For delayed assignment, one has to use (:=) (semicolon plus an equal sign), say x:=y. The literal equivalent is the SetDelayed command, for instance SetDelayed[x,y]. This means "add to the global rule base a rule, which will substitute x every time that x is encountered, by the value that y will have at that moment". So, with this kind of assignment, the right hand side is not evaluated at the moment of assignment, but is re-evaluated every time when the left-hand side appears somewhere in the program. This is the main difference between the two assignment operators, since with Set, the l.h.s. is assigned the value that the r.h.s. has at the moment of assignment, "once and for all".

"node97_4.gif" "node97_5.gif" "node97_6.gif"

Created by Wolfram Mathematica 6.0  (05 February 2009) Valid XHTML 1.1!