 codegen - Maple Programming Help

Home : Support : Online Help : Programming : codegen Package : codegen/packparams

codegen

 packparams
 pack parameters of a Maple procedure into an array
 packargs
 pack parameters of a Maple procedure into an array
 packlocals
 pack locals of a Maple procedure into an array
 swapargs
 interchange two arguments in a Maple procedure
 renamevar
 rename a variable in a Maple procedure

 Calling Sequence packparams(f, X, A) packargs(f, X, A) packlocals(f, X, A) swapargs(f, m=n) renamevar(x=y, f)

Parameters

 f - Maple procedure X - list of symbols A - name of array argument x, y - symbols (parameters in f) m, n - integers (positions of parameters in f)

Description

 • The packparams function is used to collect the parameters in the list X into one parameter, an array named A, in the Maple procedure f.
 • The packargs function is a synonym for the packparams function.
 • The packlocals function is used to collect the local variables in the list X into one local variable, an array named A, in the Maple procedure f.
 • The swapargs function is used to swap the formal parameter at position m with the formal parameter at position n in a Maple procedure.
 • The renamevar function is used to rename a (parameter, local, or global) variable x with the new name y in a Maple procedure.
 • The command with(codegen,packargs) allows the use of the abbreviated form of this command.
 • The command with(codegen,packlocals) allows the use of the abbreviated form of this command.
 • The command with(codegen,swapargs) allows the use of the abbreviated form of this command.
 • The command with(codegen,renamevar) allows the use of the abbreviated form of this command.

Examples

 > $\mathrm{with}\left(\mathrm{codegen}\right):$
 > f := proc(x,y,z) local r,s,t; r := x*z; s := y^2; t := r*s; t^2 end proc:
 > $\mathrm{packparams}\left(f,\left[x,y,z\right],A\right)$
 ${\mathbf{proc}}\left({A}{::}\left({\mathrm{array}}{}\left({1}{..}{3}\right)\right)\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{r}{,}{s}{,}{t}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{r}{:=}{A}{[}{1}{]}{*}{A}{[}{3}{]}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{s}{:=}{A}{[}{2}{]}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{t}{:=}{r}{*}{s}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{t}{^}{2}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (1)
 > $\mathrm{packlocals}\left(f,\left[s,t\right],A\right)$
 ${\mathbf{proc}}\left({x}{,}{y}{,}{z}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{A}{,}{r}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{A}{:=}{\mathrm{array}}{}\left({1}{..}{2}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{r}{:=}{x}{*}{z}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{A}{[}{1}{]}{:=}{y}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{A}{[}{2}{]}{:=}{r}{*}{A}{[}{1}{]}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{A}{[}{2}{]}{^}{2}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (2)
 > $\mathrm{swapargs}\left(f,1=2\right)$
 ${\mathbf{proc}}\left({y}{,}{x}{,}{z}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{r}{,}{s}{,}{t}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{r}{:=}{x}{*}{z}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{s}{:=}{y}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{t}{:=}{r}{*}{s}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{t}{^}{2}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (3)
 > $\mathrm{renamevar}\left(x=u,f\right)$
 ${\mathbf{proc}}\left({u}{,}{y}{,}{z}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{r}{,}{s}{,}{t}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{r}{:=}{u}{*}{z}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{s}{:=}{y}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{t}{:=}{r}{*}{s}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{t}{^}{2}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (4)
 > $\mathrm{renamevar}\left(s=x,f\right)$