{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 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 "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 }{PSTYLE "Map le Output" -1 12 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 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 60 "Co nstructing names of local variables and formal parameters " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 171 "Names of global \+ variables can be constructed by various string manipulations, e.g. con catenation. This is often very useful when you have a sequence of var iables such as " }{MPLTEXT 0 21 2 "x1" }{TEXT -1 2 ", " }{MPLTEXT 0 21 2 "x2" }{TEXT -1 44 ", ...; in a loop, you can form the names by " }{MPLTEXT 0 21 4 "x||i" }{TEXT -1 7 " where " }{MPLTEXT 0 21 1 "i" } {TEXT -1 243 " is the index. However, this does not work with local v ariables or formal parameters in a procedure: the constructed names wi ll refer to global variables. For example, the following procedure wo rks, because the names involved are all global:" }}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 66 "test1:= proc() \nlocal i;\nfor i from 1 to 3 d o x||i:= g||i od;\nend;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%&test1GR6 \"6#%\"iGF&F&?(8$\"\"\"F+\"\"$%%trueG>(%\"xGF*(%\"gGF*F&F&F&" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "test1():" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 9 "x1,x2,x3;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6% %#g1G%#g2G%#g3G" }}}{PARA 0 "" 0 "" {TEXT -1 49 "However, the next one doesn't work: in the loop, " }{MPLTEXT 0 21 4 "v||i" }{TEXT -1 6 " a nd " }{MPLTEXT 0 21 4 "p||i" }{TEXT -1 64 " will refer to global varia bles rather than the local variables " }{MPLTEXT 0 21 2 "v1" }{TEXT -1 2 ", " }{MPLTEXT 0 21 2 "v2" }{TEXT -1 2 ", " }{MPLTEXT 0 21 2 "v3 " }{TEXT -1 26 " or the formal parameters " }{MPLTEXT 0 21 2 "p1" } {TEXT -1 2 ", " }{MPLTEXT 0 21 2 "p2" }{TEXT -1 2 ", " }{MPLTEXT 0 21 2 "p3" }{TEXT -1 2 ". " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 107 "t est2:= proc(p1,p2,p3)\n local v1,v2,v3,i;\n for i from 1 to 3 do v|| i:= p||i od;\n print(v1,v2,v3);\n end;" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%&test2GR6%%#p1G%#p2G%#p3G6&%#v1G%#v2G%#v3G%\"iG6\"F/C$?(8'\"\" \"F3\"\"$%%trueG>(%\"vGF2(%\"pGF2-%&printG6%8$8%8&F/F/F/" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "test2(u,v,w);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%%#v1G%#v2G%#v3G" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "v1,v2,v3;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%%#p1G%#p2G%#p3G" } }}{PARA 0 "" 0 "" {TEXT -1 226 "The reason for this behaviour is conne cted to the way the Maple kernel processes procedure definitions. Int ernally, names are used for reference to global variables, but not loc al variables or formal parameters. For example:" }}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 37 "test3:= proc(x) local v; v:= x+g end:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 48 "pointto(disassemble(addresso f(eval(test3)))[6]);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>8$,&9$\"\"\"% \"gGF'" }}}{PARA 0 "" 0 "" {TEXT -1 82 "Thus in the internal version o f the procedure definition, the local variable name " }{MPLTEXT 0 21 1 "v" }{TEXT -1 16 " is replaced by " }{MPLTEXT 0 21 6 "LOC[1]" } {TEXT -1 32 ", and the formal parameter name " }{MPLTEXT 0 21 1 "x" } {TEXT -1 16 " is replaced by " }{MPLTEXT 0 21 7 "args[1]" }{TEXT -1 291 " (more precisely, these are special constructions which Maple int erprets as references to the first local variable and the first formal parameter). If a name is only produced when the procedure is execute d, these replacements do not occur and the name is interpreted as a gl obal variable. \027" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 12 "You can use " }{MPLTEXT 0 21 7 "args[i]" }{TEXT -1 17 " to refer to the " }{MPLTEXT 0 21 1 "i" }{TEXT -1 105 "'th formal para meter, so constructing the formal parameter names should not be necess ary. You can't use " }{MPLTEXT 0 21 7 "args[i]" }{TEXT -1 62 " on the left side of an assignment statement, but you can use " }{MPLTEXT 0 21 6 "assign" }{TEXT -1 69 " to assign values to the formal parameters (if these are declared as " }{MPLTEXT 0 21 5 "evaln" }{TEXT -1 13 " p arameters)." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 89 "test4:= proc( x::evaln,y::evaln) local i;\n for i from 1 to 2 do assign(args[i],i) \+ od\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "test4(u,v): \nu ,v;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6$\"\"\"\"\"#" }}}{PARA 0 "" 0 " " {TEXT -1 9 "However, " }{MPLTEXT 0 21 3 "LOC" }{TEXT -1 129 " can't \+ be used in the same way. You can define your own variable to stand fo r the sequence of local variables you want to index." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 118 "test5:= proc() local x1, x2, i, locals; \n locals:= x1,x2;\n for i from 1 to 2 do assign(locals[i],i) od;\n \+ x1,x2;\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "test5();" } }{PARA 11 "" 1 "" {XPPMATH 20 "6$\"\"\"\"\"#" }}}}{SECT 0 {PARA 0 "" 0 "" {TEXT 26 9 "See also:" }{TEXT -1 1 " " }{HYPERLNK 17 "||" 2 "||" "" }{TEXT -1 2 ", " }{HYPERLNK 17 "args" 2 "args" "" }{TEXT -1 2 ", " }{HYPERLNK 17 "assign" 2 "assign" "" }{TEXT -1 2 ", " }{HYPERLNK 17 "e valn" 2 "procedure,paramtype" "" }{TEXT -1 2 ", " }{HYPERLNK 17 "param eter" 2 "parameter" "" }{TEXT -1 2 ", " }{HYPERLNK 17 "procedure" 2 "p rocedure" "" }}}{SECT 0 {PARA 0 "" 0 "" {TEXT 26 22 "Maple Advisor Dat abase" }{TEXT 256 18 " R. Israel, 2000" }}}}{MARK "0 0 0" 8 } {VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }