assign - Maple Programming Help

assign

perform assignments

 Calling Sequence assign(a, B) assign(A = B) assign(t)

Parameters

 a - name or function A - name or function, or sequence of them B - expression or sequence of expressions t - list, set, or sequence of equations

Description

 • The assign(a, B) and assign(a = B) commands make the assignment $a≔B$ and return NULL.
 • The arguments are evaluated, so if a is already assigned to the name x, then the function assign(a = 3) assigns x the value $3$.
 • The assign(A=B) command, where A and B are both expression sequences with the same number of objects, assigns corresponding objects in B to objects in A, and returns NULL.
 • If the argument is a list or set of equations, then assign is applied to each equation in the list or set.
 • You can apply this function to a set of equations returned by the solve function when you want to assign the solution values to the variables.
 • The setting of kernelopts(assertlevel=2) causes type assertions to be checked. Whenever an assignment is made to a local variable with such a type assertion, the type of the right-hand side is checked after evaluation, but before the assignment is done. If the type of the right-hand side does not match, an assertion failure exception is raised.
 • The assign function can be used to set environment variables in the scope of the function calling assign.

 • The assign command is thread safe as of Maple 15, provided that the name or function being assigned to is not shared between threads.

Examples

 > $\mathrm{assign}\left(a,c\right)$
 > $\mathrm{assign}\left(a=d,b=2\right)$
 > $a,b,c$
 ${d}{,}{2}{,}{d}$ (1)

Since a and b have already been assigned, unevaluation quotes must be used.

 > $\mathrm{assign}\left(\left('a','b'\right)=\left(3,4\right)\right)$
 > $a,b,c$
 ${3}{,}{4}{,}{d}$ (2)
 > $\mathrm{assign}\left({T}_{1},x,y,z\right)$
 > ${T}_{1}$
 ${x}{,}{y}{,}{z}$ (3)
 > $s≔\mathrm{solve}\left(\left\{x+y=1,2x+y=3\right\},\left\{x,y\right\}\right)$
 ${s}{≔}\left\{{x}{=}{2}{,}{y}{=}{-1}\right\}$ (4)
 > $\mathrm{assign}\left(s\right)$
 > $x,y$
 ${2}{,}{-1}$ (5)

Examples of typed assignments

 > $\mathrm{kernelopts}\left(\mathrm{assertlevel}=2\right):$
 > F := proc(x) local a; assign(a::integer, x); return a; end proc:
 > $F\left(3.4\right)$
 > F := proc(x) local a::integer; assign(a, x); return a; end proc:
 > $F\left(3.4\right)$
 > $\mathrm{assign}\left(K::\mathrm{float},"hello"\right)$
 > $\mathrm{assign}\left(K::\mathrm{string},"hello"\right):$
 > $K$
 ${"hello"}$ (6)

assign can be used to set the value of environment variables.

 > EnvExample := proc( d ) assign( 'Digits', d ); Digits end;
 ${\mathrm{EnvExample}}{:=}{\mathbf{proc}}\left({d}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{assign}}{}\left({'}{\mathrm{Digits}}{'}{,}{d}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{Digits}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (7)
 > $\mathrm{EnvExample}\left(20\right)$
 ${20}$ (8)
 > $\mathrm{EnvExample}\left(30\right)$
 ${30}$ (9)