convert/global - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

Home : Support : Online Help : Programming : Data Types : Conversion : convert/global

convert/global

convert an expression to a global name

 Calling Sequence convert(e, 'global', opts)

Parameters

 e - any Maple object opts - equation(s) of the form option=value where option is one of expression, assign, reset, or unique; specify options for the conversion

Description

 • The convert(e, global) function converts any local symbols in the expression e to global symbols.
 • Note that, because the name global is a Maple keyword, it must be enclosed in backquotes, as demonstrated by the examples below.
 • The opts argument can contain one or more of the following equations that set how symbols are converted to globals.
 assign = truefalse
 If this option is set to true, then if a local variable is assigned, the global will be assigned to the same object.
 expression = truefalse
 If this option is set to true, then the entire expression will be converted into a global variable and all other options will be ignored.
 reset = truefalse
 If this option is set to true, then any new globals generated by the option unique will be reset, otherwise, on subsequent calls, the attached integers will grow in size. This option is only useful in conjunction with the option unique.
 unique = truefalse
 If this option is set to true, then if two local variables have the same appearance, they will be converted to different global variables by appending digits to the end of subsequent global variable.

Examples

assign x, y, z to three locals: a, a, and b

 > $x≔\mathrm{convert}\left(a,'\mathrm{local}'\right)$
 ${x}{≔}{a}$ (1)
 > $y≔\mathrm{convert}\left(a,'\mathrm{local}'\right)$
 ${y}{≔}{a}$ (2)
 > $z≔\mathrm{convert}\left(b,'\mathrm{local}'\right)$
 ${z}{≔}{b}$ (3)
 > $\mathrm{convert}\left(x+y+z,'\mathrm{global}'\right)$
 ${2}{}{a}{+}{b}$ (4)
 > $\mathrm{convert}\left(x+y+z,'\mathrm{global}',\mathrm{unique}\right)$
 ${a}{+}{\mathrm{a0}}{+}{b}$ (5)

assign a procedure to the local a

 > assign(x, proc(s) sin(s) + s end);
 > $f≔\mathrm{convert}\left(x,\mathrm{global}\right)$
 ${f}{≔}{a}$ (6)
 > $f\left(3.2\right)$
 ${a}{}\left({3.2}\right)$ (7)
 > $f≔\mathrm{convert}\left(x,\mathrm{global},\mathrm{assign}\right)$
 ${f}{≔}{a}$ (8)
 > $f\left(3.2\right)$
 ${3.141625857}$ (9)
 > $\mathrm{convert}\left(x+y+z,'\mathrm{global}',\mathrm{unique}\right)$
 ${\mathrm{a1}}{+}{\mathrm{a2}}{+}{\mathrm{b0}}$ (10)
 > $\mathrm{convert}\left(x+y+z,'\mathrm{global}',\mathrm{unique},\mathrm{reset}\right)$
 ${\mathrm{a0}}{+}{\mathrm{a1}}{+}{b}$ (11)
 > $\mathrm{sym}≔\mathrm{convert}\left(x+y+z,'\mathrm{global}',\mathrm{expression}\right)$
 ${\mathrm{sym}}{≔}{\mathrm{a+a+b}}$ (12)
 > $\mathrm{type}\left(\mathrm{sym},\mathrm{symbol}\right)$
 ${\mathrm{true}}$ (13)

 See Also