{VERSION 3 0 "IBM INTEL NT" "3.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 }{CSTYLE "Hyperlink" -1 17 "" 0 1 0 128 128 1 0 0 1 0 0 0 0 0 0 } {CSTYLE "2D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 }{CSTYLE " " 0 21 "" 0 1 0 0 0 1 0 0 0 0 2 0 0 0 0 }{CSTYLE "Help Heading" -1 26 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 }{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Maple Output" 0 11 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 3 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {PARA 0 "" 0 "" {TEXT -1 0 "" }}{SECT 0 {PARA 0 "" 0 "" {TEXT 26 7 "Advice:" }{TEXT -1 27 " Assignments do not commute" }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 366 "The order in whic h you do things is often important in Maple, sometimes in rather surpr ising ways. One of these ways is due to the fact that the right side \+ of an assignment statement is evaluated: the variable on the left is a ssigned the value that the right side evaluates to, not the right side itself. For example, consider the following sequence of statements: " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "p:= 1:\nq:= 1+p;" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"qG\"\"#" }}}{PARA 0 "" 0 "" {TEXT -1 31 "A reasonable enough result: if " }{MPLTEXT 0 21 1 "p" }{TEXT -1 12 " is 1, then " }{MPLTEXT 0 21 1 "q" }{TEXT -1 51 " should be 2. \+ But notice that what is assigned to " }{MPLTEXT 0 21 1 "q" }{TEXT -1 23 " involves the value of " }{MPLTEXT 0 21 1 "p" }{TEXT -1 57 ", not \+ the variable itself. Maple does not remember that " }{MPLTEXT 0 21 1 "q" }{TEXT -1 19 " was defined using " }{MPLTEXT 0 21 1 "p" }{TEXT -1 8 ", so if " }{MPLTEXT 0 21 1 "p" }{TEXT -1 55 " is later given a diff erent value this will not affect " }{MPLTEXT 0 21 1 "q" }{TEXT -1 2 ". " }{TEXT -1 1 " " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "p:= 3:\n q;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"#" }}}{PARA 0 "" 0 "" {TEXT -1 60 "Suppose, however, the order of definitions is reversed, and " } {MPLTEXT 0 21 1 "q" }{TEXT -1 24 " is defined in terms of " }{MPLTEXT 0 21 1 "p" }{TEXT -1 7 " while " }{MPLTEXT 0 21 1 "p" }{TEXT -1 45 " h as no assigned value. First we \"unassign\" " }{MPLTEXT 0 21 1 "p" } {TEXT -1 1 "." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "p:= 'p':\nq := 1+p;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"qG,&\"\"\"F&%\"pGF&" }} }{PARA 0 "" 0 "" {TEXT -1 4 "Now " }{MPLTEXT 0 21 1 "q" }{TEXT -1 15 " is defined as " }{MPLTEXT 0 21 3 "1+p" }{TEXT -1 8 ". When " } {MPLTEXT 0 21 1 "p" }{TEXT -1 39 " is assigned values, the definition \+ of " }{MPLTEXT 0 21 1 "q" }{TEXT -1 24 " is unchanged, but when " } {MPLTEXT 0 21 1 "q" }{TEXT -1 51 " is evaluated the result uses the cu rrent value of " }{MPLTEXT 0 21 1 "p" }{TEXT -1 2 ". " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "p:= 1: \nq;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"#" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "p:= 3: \nq; " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"%" }}}{PARA 0 "" 0 "" {TEXT -1 95 "Matters are complicated somewhat by arrays and procedures, whic h have special evaluation rules." }}{PARA 0 "" 0 "" {TEXT -1 16 "For a rrays, see " }{HYPERLNK 17 "Last name evaluation" 2 "Last_name_evaluat ion" "" }{TEXT -1 42 ". For local variables in procedures, see " } {HYPERLNK 17 "One level evaluation for local variables" 2 "One_level_e valuation_for_local_variables" "" }{TEXT -1 1 "." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 41 "A procedure or function d efinition using " }{MPLTEXT 0 21 4 "proc" }{TEXT -1 4 " or " } {MPLTEXT 0 21 2 "->" }{TEXT -1 195 " is not evaluated at the time the \+ procedure is defined, but only when it is called. Thus global variabl es used in the definition are always evaluated using the current value s of those variables." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "qpr oc:= x -> x+p:" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "p:= 5:\nqproc(1); " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"'" }}}{PARA 0 "" 0 "" {TEXT -1 102 "If you wish to make a definition using the value of a variable at the time of definition, you can use " }{MPLTEXT 0 21 7 "unapply" } {TEXT -1 4 " or " }{MPLTEXT 0 21 4 "subs" }{TEXT -1 59 ". Thus each o f the following procedures uses the value of " }{MPLTEXT 0 21 1 "p" } {TEXT -1 35 " (which currently happens to be 5):" }}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 24 "qproc2:= unapply(x+p,x);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%'qproc2GR6#%\"xG6\"6$%)operatorG%&arrowGF(,&9$\"\"\" \"\"&F.F(F(6\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "qproc3:= \+ subs(X=p, (x -> x+X));" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%'qproc3GR6 #%\"xG6\"6$%)operatorG%&arrowGF(,&9$\"\"\"\"\"&F.F(F(6\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "p:= 7: qproc2(1), qproc3(1);" }} {PARA 11 "" 1 "" {XPPMATH 20 "6$\"\"'F#" }}}}{SECT 0 {PARA 0 "" 0 "" {TEXT 26 9 "See also:" }{TEXT -1 1 " " }{HYPERLNK 17 "assignment" 2 "a ssignment" "" }{TEXT -1 2 ", " }{HYPERLNK 17 "eval" 2 "eval" "" } {TEXT -1 2 ", " }{HYPERLNK 17 "subs" 2 "subs" "" }{TEXT -1 2 ", " } {HYPERLNK 17 "unapply" 2 "unapply" "" }{TEXT -1 2 ", " }{HYPERLNK 17 " Last name evaluation" 2 "Last_name_evaluation" "" }{TEXT -1 2 ", " } {HYPERLNK 17 "One level evaluation for local variables" 2 "One_level_e valuation_for_local_variables" "" }}}{SECT 0 {PARA 0 "" 0 "" {TEXT 26 24 "Maple Advisor Database, " }{TEXT -1 15 " R. Israel 1997" }}}} {MARK "3" 0 }{VIEWOPTS 1 1 0 1 1 1803 }