assign
perform assignments
Calling Sequence
Parameters
Description
Thread Safety
Examples
assign(a, B)
assign(A = B)
assign(t)
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
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.
For more information on thread safety, see index/threadsafe.
assign⁡a,c
assign⁡a=d,b=2
a,b,c
d,2,d
Since a and b have already been assigned, unevaluation quotes must be used.
assign⁡a,b=3,4
3,4,d
assign⁡T1,x,y,z
T1
x,y,z
s≔solve⁡x+y=1,2⁢x+y=3,x,y
s≔x=2,y=−1
assign⁡s
x,y
2,−1
Examples of typed assignments
kernelopts⁡assertlevel=2:
F := proc(x) local a; assign(a::integer, x); return a; end proc:
F⁡3.4
Error, (in F) assertion failed in assignment, expected integer, got 3.4
F := proc(x) local a::integer; assign(a, x); return a; end proc:
assign⁡K::float,hello
Error, (in assign) assertion failed in assignment, expected float, got hello
assign⁡K::string,hello:
K
hello
assign can be used to set the value of environment variables.
EnvExample := proc( d ) assign( 'Digits', d ); Digits end;
EnvExample ≔ procdassign⁡'Digits',d;Digitsend proc
EnvExample⁡20
20
EnvExample⁡30
30
See Also
:=
::
kernelopts
type
unassign
uneval
Download Help Document