RosettaCodeData/Task/History-variables/M2000-Interpreter/history-variables-1.m2000
2023-07-01 13:44:08 -04:00

38 lines
1,009 B
Text

Flush ' empty curtrent stack
\\ a is a pointer to a new stack object
a=stack:=1,2@,3%
Print Len(A)=3
For i=1 to Len(a) {
Print StackType$(a, i)="Number"
}
b=stack
Print len(b)=0
Push 1, 2 \\ to current stack
Stack b {
\\ make b the current stack
Data 1, 2, 3
} ' Data add to bottom
\\ now current stack get the old object
Stack b {Push 1, 2, 3 } ' Push add to top, so 3 is at top
Stack b {
While not empty {
Read k ' Read used to pop value to a variable
\\ number pop value in an expression
Print k, number, ' 3 2 1 1 2 3
}
Print
}
z=[] ' [] pop all values from current stack to a new stack, and return a pointer
Print z ' 2 1
z=Stack(a, z,a, z) ' merge stack objects, to a new one, preserve a and z
Print Len(z)
\\ empty a using a new object
a=stack
b=stack:=1,2,3
\\ z has two stack objects
z=stack:= a, b
Stack b { data 1000}
b=stack ' b point to a new stack
\\ we get pointer back
b=stackitem(z, 2)
Print stackitem(b, 4)=1000