24.5.11 Arrays as Stacks

Array values can be manipulated as stacks using two operators: apush and apop.

The apush operator gets an array and a value and appends the value into the array. Note it has a destructive side-effect in the array value, and also it returns the modified value:

(poke) var a = [1,2,3]
(poke) apush (a, 4)
[1,2,3,4]
(poke) a
[1,2,3,4]

the apop operators gets an array and removes the last value of the array. If the given array is empty then E_out_of_bounds is raised. As with apush, the operation has the side effect of modifying the given array and also it returns the popped element:

(poke) var a = [1,2,3]
(poke) apop (a)
3
(poke) apop (a)
2
(poke) apop (a)
1
(poke) apop (a)
unhandled out of bounds exception