RosettaCodeData/Task/Null-object/M2000-Interpreter/null-object-2.m2000

55 lines
1.4 KiB
Plaintext

Module CheckContainers {
\\ Arrays (A() and B() are value types)
Dim A(10)=1, B()
\\ B() get a copy of A(), is not a reference type
B()=A()
\\ we make a pointer to Array
B=A()
\\ now B is a reference type object
Print Len(B)=10 ' ten items
B+=10
Print A(3)=11, A(7)=11
\\ we can change pointer using a pointer to an empty array
B=(,)
\\ we can erase A() and B()
Dim A(0), B(0)
Print Len(A())=0, Len(B())=0
Print Len(B)=0
B=(123,)
\\ B() is a value type so get a copy
B()=B
Print Len(B)=1, B(0)=123
\\ Using Clear we pass a new empty array
Clear B
Print Type$(B)="mArray"
Print Len(B)=1, B(0)=123
\\ Inventrories. Keys must be unique (for normal inventories)
Inventory M=1,2,3,4:=400,5
Print M
Clear M
Inventory M=1,2,3,4,5
Print M
\\ Inventory Queue can have same keys.
Inventory Queue N=1,1,2:="old",2:="ok",3
If Exist(N,2) Then Print Eval$(N)="ok", Eval(N!)=3 ' 4th item
Clear N
Print Len(N)=0, Type$(N)="Inventory"
\\ Stack Object
Z=Stack:=1,2,3
Stack Z {
While not empty {Print Number}
}
Print Len(Z)=0
Z=Stack((Stack:=1,2,3,4),Stack:=20,30,40 )
Print Len(Z)=7
Print Z ' 1 2 3 4 20 30 49
Z=Stack ' This is an empty stacl
Print Len(Z)=0
Print Type$(Z)="mStiva"
}
CheckContainers