{VERSION 4 0 "IBM INTEL NT" "4.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "Hyperlink" -1 17 "" 0 1 0 128 128 1 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "2D Comment" 2 18 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "2D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" 0 21 "" 0 1 0 0 0 1 0 0 0 0 2 0 0 0 0 1 }{CSTYLE "Help Head ing" -1 26 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 256 "Tim es" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }{PSTYLE "Normal" -1 0 1 {CSTYLE " " -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 1" 0 3 1 {CSTYLE "" -1 -1 "" 1 18 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }1 0 0 0 8 4 0 0 0 0 0 0 -1 0 }{PSTYLE "Maple Output " -1 11 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 } 3 3 0 0 0 0 1 0 1 0 2 2 0 1 }} {SECT 0 {SECT 0 {PARA 0 "" 0 "" {TEXT 26 8 "Advice: " }{TEXT -1 47 "Do n't use formal parameters as local variables " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 423 "It is possible to assign a value to a formal parameter of a procedure (assuming the actual par ameter is something that can be assigned a value). This is useful bec ause it allows such parameters to be used for output as well as input. However, because of Maple's evaluation rules, you should not attempt to access that assigned value within the procedure. Thus the formal \+ parameter should not be used as a local variable." }}}{SECT 0 {PARA 3 "" 0 "" {TEXT 26 9 "Examples:" }{TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 37 "This one is OK: the formal parameter " }{MPLTEXT 0 21 1 "c" } {TEXT -1 26 " is used for output. The " }{MPLTEXT 0 21 5 "evaln" } {TEXT -1 106 " means that the actual parameter will be evaluated only \+ to a name, so any value that the actual parameter " }{MPLTEXT 0 21 1 " u" }{TEXT -1 34 " already has will be overwritten. " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 55 "f:= proc(a,b,c::evaln) c:= a+b end:\nu:= v: f(1,2,u):\nu;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"$" }}}{PARA 0 " " 0 "" {TEXT -1 174 "The next one does not work as expected: the forma l parameter is first assigned a value, but then an attempt is made to \+ access that value to form the result. It doesn't work." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 46 "f:= proc(a,b::evaln) b:= a+1; b-1 e nd:\nf(c,d);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,&%\"dG\"\"\"F%!\"\"" }}}{PARA 0 "" 0 "" {TEXT -1 250 "The reason is Maple's evaluation rule s for formal parameters. The actual parameter is evaluated to the app ropriate level and then substituted for the formal parameter in the bo dy of the procedure. Thus in this case the body of the procedure beco mes" }}{EXCHG {PARA 0 "" 0 "" {MPLTEXT 0 21 12 "d:= c+1; d-1" }}} {PARA 0 "" 0 "" {TEXT -1 146 "But these parameters are not evaluated a gain during the execution of the procedure. Thus, even though after t he first statement of the procedure " }{MPLTEXT 0 21 1 "d" }{TEXT -1 15 " has the value " }{XPPEDIT 18 0 "c+1" "6#,&%\"cG\"\"\"F%F%" } {TEXT -1 6 ", the " }{MPLTEXT 0 21 1 "d" }{TEXT -1 45 " in the second \+ statement is not evaluated to " }{XPPEDIT 18 0 "c+1" "6#,&%\"cG\"\"\"F %F%" }{TEXT -1 16 " but is left as " }{MPLTEXT 0 21 1 "d" }{TEXT -1 1 "." }}{PARA 0 "" 0 "" {TEXT -1 323 "There are various situations in wh ich this behaviour may or may not be harmless, but the simplest rule t o avoid any trouble is: after assigning a value to a formal parameter, don't try to access the value of that parameter. Instead, use a loca l variable to store any value that you will need to access. Thus you \+ could say" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "f:= proc(a,b::e valn) local v; v:=a+1; b:= v; v-1 end:\nf(c,d);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%\"cG" }}}}{SECT 0 {PARA 0 "" 0 "" {TEXT 26 9 "See also :" }{TEXT -1 1 " " }{TEXT -1 1 " " }{HYPERLNK 17 "evaln" 2 "procedure, paramtype" "" }{TEXT -1 2 ", " }{HYPERLNK 17 "parameter" 2 "parameter " "" }{TEXT -1 2 ", " }{HYPERLNK 17 "procedure" 2 "procedure" "" }}} {SECT 0 {PARA 0 "" 0 "" {TEXT 26 22 "Maple Advisor Database" }{TEXT 256 18 " R. Israel, 2000" }}}}{MARK "2 0 0" 4 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }