Assignment: Difference between revisions

Jump to navigation Jump to search
51 bytes added ,  01:29, 13 February 2022
APL uses 6-space indents
mNo edit summary
(APL uses 6-space indents)
Line 4: Line 4:
Common examples (boxing on, and [[index origin]] is 0):
Common examples (boxing on, and [[index origin]] is 0):
<source lang=apl>
<source lang=apl>
  ⎕←mat←(1 2 3)(1 2 3)
      ⎕←mat←(1 2 3)(1 2 3)
┌─────┬─────┐
┌─────┬─────┐
│1 2 3│1 2 3│
│1 2 3│1 2 3│
Line 12: Line 12:
Individual elements can be updated using index assignment:
Individual elements can be updated using index assignment:
<source lang=apl>
<source lang=apl>
  mat[0]←1
      mat[0]←1
  mat
      mat
┌─┬─────┐
┌─┬─────┐
│1│1 2 3│
│1│1 2 3│
Line 20: Line 20:
A semicolon is necessary when dealing with a [[matrix]]:
A semicolon is necessary when dealing with a [[matrix]]:
<source lang=apl>
<source lang=apl>
  mat←3 3⍴⍳9
      mat←3 3⍴⍳9
  mat
      mat
0 1 2
0 1 2
3 4 5
3 4 5
6 7 8
6 7 8
  mat[0 1;]
      mat[0 1;]
0 1 2
0 1 2
3 4 5
3 4 5
  mat[0 1;0 1]←0
      mat[0 1;0 1]←0
  mat
      mat
0 0 2
0 0 2
0 0 5
0 0 5
Line 38: Line 38:
Some dialects allow placing a function the the immediate left of the assignment arrow:
Some dialects allow placing a function the the immediate left of the assignment arrow:
<source lang=apl>
<source lang=apl>
  var←42
      var←42
  var+←1
      var+←1
  var
      var
43
43
</source>
</source>
Line 47: Line 47:
Modified assignment can also be combined with indexed assignment:
Modified assignment can also be combined with indexed assignment:
<source lang=apl>
<source lang=apl>
  mat←3 3⍴0
      mat←3 3⍴0
  mat
      mat
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
  mat[0 1;1]+←1
      mat[0 1;1]+←1
  mat
      mat
0 1 0
0 1 0
0 1 0
0 1 0
0 0 0
0 0 0
  mat[1;1],←'x'
      mat[1;1],←'x'
  mat
      mat
0 1 0
0 1 0
0 x 0
0 x 0

Navigation menu