The assignment Statement - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Operations : Assignment : assignment

The assignment Statement

 

Description

Examples

Description

• 

lhs := rhs;

• 

The assignment operator := assigns to the lhs the value of rhs. The left-hand side of the assignment operator must be a name, indexed-name, function call, or expression sequence of these.

• 

The assignment statement functions as follows.

1. 

The left-hand side is resolved to a name. (For more information, see the evaln function).

2. 

The right-hand side is evaluated as an expression.

3. 

The assignment is performed. The value of the assignment statement is the right-hand side.

• 

If the left-hand side is a sequence of names, the right-hand side must evaluate to a sequence of expressions with the same number of components as the left-hand side.  The sequence of assignments are processed in the following order.  First, all of the right-hand side expressions are evaluated.  Then in a left to right pairwise manner the names on the left-hand side are evaluated and the matching value on the right-hand side is assigned to it.

• 

Local variables can be declared with type assertions. The syntax is the same as that used for parameters. Whenever an assignment is made to a local variables 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.

  

Similarly, the left-hand side of any assignment can contain a type assertion that is checked before the assignment is carried out.

• 

The setting of kernelopts(assertlevel) controls whether these type assertions are checked. Settings are described as follows.

  

0 - Turns off all assertion checking.

  

1 - Checks only assertions made using the ASSERT function.

  

2 - Checks ASSERT assertions, and assignment-type assertions.

Examples

i1

i:=1

(1)

i

1

(2)

ai2

ai:=2

(3)

ai

2

(4)

f10

f1:=0

(5)

f1

0

(6)

a,b2,3

a,b:=2,3

(7)

a,bb,a

a,b:=3,2

(8)

g := proc(x) (x-1,x+1) end proc;

g:=procxx1,x+1end proc

(9)

s,tg10

s,t:=9,11

(10)

j,cj,fj1,2,3

j,cj,fj:=1,2,3

(11)

printc

table1=2

(12)

f1

3

(13)

Examples of typed assignments with assertion failures.

kerneloptsassertlevel=2:

F := proc(x) local a::integer; a := x end proc:

F3.4

Error, (in myassign) assertion failed in assignment, expected integer, got 3.4

b::float1,2,3,4,5

Error, (in myassign) assertion failed in assignment, expected float, got [1, 2, 3, 4, 5]

See Also

::

assign

assigned

index/expression

kernelopts

type

unassign

Using the Variable Manager

Variable Manager

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam