Here a testcase that also shows effects of enlarging the array (basically whenever one dimension
gets its size increased).
a=.array~new
a[1,1]="1,1" /* first usage, makes array a two dimensional array */
say "after setting a[1,1]:" pp(a[1,1])
a[2,1]="2,1"
say "after setting a[2,1]:" pp(a[2,1])
a[2,2]="2,2"
say "after setting a[2,2]:" pp(a[2,2])
a[2,3]="2,3"
say "after setting a[2,3]:" pp(a[2,3])
say
call dump0 a
say
say center(" now enlarging array, because of a[5,3]='5,3' ", 79, "=")
a[4,5]="4,5"
say "after setting a[4,5]:" pp(a[4,5]) "/" "a[2,1]:" pp(a[2,1]) "error <--
dimension(1) raised to 4, dimension(2) to 5"
say
call dump0 a
say
say center(" now enlarging array, because of a[5,3]='5,3' ", 79, "=")
say
a~put("5,3", 5, 3) /* use PUT instead of []= */
say "a[2,1]:" pp(a[2,1]) "/" "a[4,5]:" pp(a[4,5]) "/" "a[5,3]:" pp(a[5,3])
say
call dump0 a
say
say center(" now enlarging array, because of a[6,7]='6,7' ", 79, "=")
say
a~put("6,7", 6, 7) /* use PUT instead of []= */
say "a[2,1]:" pp(a[2,1]) "/" "a[4,5]:" pp(a[4,5]) "/" "a[5,3]:" pp(a[5,3]) "/"
"a[6,7]:" pp(a[6,7])
say
say "a[2,1]:" pp(a[2,1])
say "a[4,5]:" pp(a[4,5])
say "a[5,3]:" pp(a[5,3])
call dump0 a
say
say "a[2,1]:" pp(a[2,1])
say "a[4,5]:" pp(a[4,5])
say "a[5,3]:" pp(a[5,3])
say "a[6,7]:" pp(a[6,7])
::routine dump0
use arg a
say "dump0: a~dimension:" pp(a~dimension) "/" "a~dimension(1):" pp(a~dimension(1))
"/" "a~dimension(2):" pp(a~dimension(2))
say "dump0: a~items :" pp(a~items) "/" "a~size :"
pp(a~size)
tab="09"x
say
element=1
do i=1 to a~dimension(1)
do k=1 to a~dimension(2)
-- if \a[i,k]~isNil then
say tab "#" element~right(2)":" "a["i","k"]:" a[i,k]
element+=1
end
end
say
::routine pp
return "["arg(1)"]"
Here the output of running the above script:
after setting a[1,1]: [1,1]
after setting a[2,1]: [2,1]
after setting a[2,2]: [2,2]
after setting a[2,3]: [2,3]
dump0: a~dimension: [2] / a~dimension(1): [2] / a~dimension(2): [3]
dump0: a~items : [4] / a~size : [6]
# 1: a[1,1]: 1,1
# 2: a[1,2]: The NIL object
# 3: a[1,3]: The NIL object
*# 4:* a[2,1]:*2,1*
# 5: a[2,2]: 2,2
# 6: a[2,3]: 2,3
================ now enlarging array, because of a[5,3]='5,3'
=================
after setting a[4,5]: [4,5] //a[2,1]: [2,3]/ error <-- dimension(1) raised
to 4, dimension(2) to 5
dump0: a~dimension: [2] / a~dimension(1): [4] / a~dimension(2): [5]
dump0: a~items : [5] / a~size : [20]
# 1: a[1,1]: 1,1
# 2: a[1,2]: The NIL object
# 3: a[1,3]: The NIL object
*# 4:* a[1,4]:*2,1*
# 5: a[1,5]: 2,2
# 6: a[2,1]: 2,3
# 7: a[2,2]: The NIL object
# 8: a[2,3]: The NIL object
# 9: a[2,4]: The NIL object
# 10: a[2,5]: The NIL object
# 11: a[3,1]: The NIL object
# 12: a[3,2]: The NIL object
# 13: a[3,3]: The NIL object
# 14: a[3,4]: The NIL object
# 15: a[3,5]: The NIL object
# 16: a[4,1]: The NIL object
# 17: a[4,2]: The NIL object
# 18: a[4,3]: The NIL object
# 19: a[4,4]: The NIL object
*# 20:* a[4,5]:*4,5*
================ now enlarging array, because of a[5,3]='5,3'
=================
/a[2,1]: [2,3]/ / a[4,5]: [4,5] / a[5,3]: [5,3]
dump0: a~dimension: [2] / a~dimension(1): [5] / a~dimension(2): [5]
dump0: a~items : [6] / a~size : [25]
# 1: a[1,1]: 1,1
# 2: a[1,2]: The NIL object
# 3: a[1,3]: The NIL object
*# 4:* a[1,4]:*2,1*
# 5: a[1,5]: 2,2
# 6: a[2,1]: 2,3
# 7: a[2,2]: The NIL object
# 8: a[2,3]: The NIL object
# 9: a[2,4]: The NIL object
# 10: a[2,5]: The NIL object
# 11: a[3,1]: The NIL object
# 12: a[3,2]: The NIL object
# 13: a[3,3]: The NIL object
# 14: a[3,4]: The NIL object
# 15: a[3,5]: The NIL object
# 16: a[4,1]: The NIL object
# 17: a[4,2]: The NIL object
# 18: a[4,3]: The NIL object
# 19: a[4,4]: The NIL object
*# 20:* a[4,5]:*4,5*
# 21: a[5,1]: The NIL object
# 22: a[5,2]: The NIL object
*# 23:* a[5,3]:*5,3*
# 24: a[5,4]: The NIL object
# 25: a[5,5]: The NIL object
================ now enlarging array, because of a[6,7]='6,7'
=================
/a[2,1]: [The NIL object] / a[4,5]: [The NIL object] / a[5,3]: [The NIL
object]/ / a[6,7]: [6,7]
a[2,1]: [The NIL object]
a[4,5]: [The NIL object]
a[5,3]: [The NIL object]
dump0: a~dimension: [2] / a~dimension(1): [6] / a~dimension(2): [7]
dump0: a~items : [7] / a~size : [42]
# 1: a[1,1]: 1,1
# 2: a[1,2]: The NIL object
# 3: a[1,3]: The NIL object
*# 4*: a[1,4]:*2,1*
# 5: a[1,5]: 2,2
# 6: a[1,6]: 2,3
# 7: a[1,7]: The NIL object
# 8: a[2,1]: The NIL object
# 9: a[2,2]: The NIL object
# 10: a[2,3]: The NIL object
# 11: a[2,4]: The NIL object
# 12: a[2,5]: The NIL object
# 13: a[2,6]: The NIL object
# 14: a[2,7]: The NIL object
# 15: a[3,1]: The NIL object
# 16: a[3,2]: The NIL object
# 17: a[3,3]: The NIL object
# 18: a[3,4]: The NIL object
# 19: a[3,5]: The NIL object
*# 20:* a[3,6]:*4,5*
# 21: a[3,7]: The NIL object
# 22: a[4,1]: The NIL object
*# 23:* a[4,2]:*5,3*
# 24: a[4,3]: The NIL object
# 25: a[4,4]: The NIL object
# 26: a[4,5]: The NIL object
# 27: a[4,6]: The NIL object
# 28: a[4,7]: The NIL object
# 29: a[5,1]: The NIL object
# 30: a[5,2]: The NIL object
# 31: a[5,3]: The NIL object
# 32: a[5,4]: The NIL object
# 33: a[5,5]: The NIL object
# 34: a[5,6]: The NIL object
# 35: a[5,7]: The NIL object
# 36: a[6,1]: The NIL object
# 37: a[6,2]: The NIL object
# 38: a[6,3]: The NIL object
# 39: a[6,4]: The NIL object
# 40: a[6,5]: The NIL object
# 41: a[6,6]: The NIL object
*# 42:* a[6,7]:*6,7*
a[2,1]: [The NIL object]
a[4,5]: [The NIL object]
a[5,3]: [The NIL object]
a[6,7]: [6,7]
In the loop the values occur at the same "element positions" (iterations of the
loop).
---rony