Put item on a stack

push list expression

A list can be used to implement a stack (LIFO, a "last in, first out" stack). Use push instruction to put the result of expression on a stack (as the first item in a list) and pop instruction to remove and return an item from a stack.


make "stos []
for [i 1 3] [push :stos :i print :stos]
print "|***|
while not empty? :stos [(print pop :stos :stos)]


[2 1]
[3 2 1]
3 [2 1]
2 [1]
1 []

See also:

pop - return item from a stack

Table of content