focus expression text field at startup -> version 1.2
[LeanCalc.git] / help / assign
1 NAME
2     =
3
4 SYNOPSIS
5     a = b
6     a = {e_1, e_2, ...[ { ... } ] }
7
8 TYPES
9     a                   lvalue, current value a structure in { } case
10
11     b                   expression
12
13     e_0, e_1, ...       expressions, blanks, or initializer lists
14
15
16     return              lvalue (a)
17
18 DESCRIPTION
19     Here an lvalue is either a simple variable specified by an identifier,
20     or an element of an existing structure specified by one or more
21     qualifiers following an identifier.
22
23     An initializer list is a comma-separated list enclosed in braces as in
24
25                 {e_0, e_1, ... }
26
27     where each e_i is an expression, blank or initializer list.
28
29     a = b evaluates b, assigns its value to a, and returns a.
30
31     a = {e_0, e_1, ... } where the e_i are expressions or blanks,
32     requires the current value of a to be a matrix, list
33     or object with at least as many elements as listed e_i.  Each non-blank
34     e_i is evaluated and its value is assigned to a[[i]]; elements a[[i]]
35     corresponding to blank e_i are unchanged.
36
37     If, in a = {e_0, e_1, ...}, e_i is an initializer list, as in
38     {e_i_0, e_1_1, ...}, the corresponding a[[i]] is to be a matrix, list
39     or object with at least as many elements as listed e_i_j.  Depending on
40     whether e_i_j is an expression, blank, or initializer list, one, no, or
41     possibly more than one assignment, is made to a[[i]][[j]] or, if
42     relevant and possible, its elements.
43
44     In simple assignments, = associates from right to left so that, for
45     example,
46
47                 a = b = c
48
49     has the effect of a = (b = c) and results in assigning the value of c
50     to both a and b.  The expression (a = b) = c is acceptable, but has the
51     effect of a = b; a = c; in which the first assignment is superseded by
52     the second.
53
54     In initializations, = { ...} associates from left to right so that,
55     for example,
56
57                 a = {e_0, ... } = {v_0, ...}
58
59     first assigns e_0, ... to the elements of a, and then assigns v_0, ...
60     to the result.
61
62     If there are side effects in the evaluations involved in executing a = b,
63     it should be noted that the order of evaluations is: first the address
64     for a, then the value of b, and finally the assignment.  For example if
65     A is a matrix and i = 0, then the assignment in A[i++] = A[i] is
66     that of A[0] = A[1].
67
68     If, in execution of a = b, a is changed by the evaluation of b, the
69     value of b may be stored in an unintended or inaccessible location.  For
70     example,
71                 mat A[2]= {1,2};
72                 A[0] = (A = 3);
73
74     results in the value 3 being stored not only as the new value for A
75     but also at the now unnamed location earlier used for A[0].
76
77
78 EXAMPLE
79     > b = 3+1
80     > a = b
81     > print a, b
82     4 4
83
84     > obj point {x,y}
85     > mat A[3] = {1, list(2,3), obj point = {4,5}}
86
87     > A[1][[0]] = 6; A[2].x = 7
88     > print A[1]
89
90     list (2 elements, 2 nonzero):
91         [[0]] = 6
92         [[1]] = 3
93
94     > print A[2]
95     obj point {7, 5}
96
97     > A = {A[2], , {9,10}}
98     > print A[0]
99     obj point {7, 5}
100
101     > print A[2]
102     obj point {9, 10}
103
104     > A = {, {2}}
105     print A[1]
106
107     list (2 elements, 2 nonzero):
108         [[0]] = 2
109         [[1]] = 3
110
111 LIMITS
112     none
113
114 LINK LIBRARY
115     none
116
117 SEE ALSO
118     swap, quomod
119