Null object: Difference between revisions

no edit summary
(Added AutoIt Example)
No edit summary
Line 867:
print(isnil)
</lang>
 
=={{header|M2000 Interpreter}}==
===For Com Objects===
There is a Nothing to assign to a COM object to released (but time to actually released depends from system). A com pointer can't get another value (only the first value, and the Nothing at the end).
<lang M2000 Interpreter>
Module CheckWord {
Declare Alfa "WORD.APPLICATION"
Declare Alfa Nothing
Print Type$(Alfa)="Nothing"
Try ok {
Declare Alfa "WORD.APPLICATION"
\\ we can't declare again Alfa
}
If Not Ok Then Print Error$ ' return Bad Object declaration
}
CheckWord
</lang>
===For Containers===
Container's pointers (for arrays, inventories, stack) we have to assign an empty container, there is not a null one.
 
<lang M2000 Interpreter>
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
</lang>
===For Groups==
Groups are value types, but we can make reference to them,or pointer to them
 
A Named referenced can't get a new reference
 
A pointer to a named group is actual a reference, and can change type and reference
 
A pointer to a copy of group (as float group) is actually a pointer to group.
 
Pointers to groups can be point to an empty Group, assigning a 0& value (a long type)
 
 
<lang M2000 Interpreter>
Module CheckGroup {
\\ Group Objects
Class Beta {x=10, z=3}
G=Beta()
Group G {
\\ we can add a member
y=2
}
Print Group.Count(G)=3 ' 3 members ' not counting modules/functions/operators
\\ G is a value type
Print G.x=10
G.x+=20
\\ we can make a pointer to G
pG->G
Print pG=>x=30
\\ we can assign a null, which give a pointer to an empty group
pG->0&
Print type$(pG)="Group"
\\ make a pointerto a copy of G
pG->(G)
G.x=0
Print pG=>x=30
\\ assign new value to G, using a copy of pG
G=Group(pG)
Print G.x=30
pG1=pG
pG->0&
Print pG1=>x=30, Valid(pG=>x)=False
pG->G
\\ we can clear G, but clear only te relationship with G.x, G.y, G.z
Clear G
Print Group.Count(G)=0
\\ G.x exist.
\\ pG=>x also exist becase pG hold actual name of G
Print G.x, pG=>x
pG1=>x++
For pG1 {.y+=10 : .z+=40}
\\ we can reload the group list
G=Group(pG1)
Print Group.Count(G)=3
For G {
Print .x, .y, .z ' 31 12 43
}
\\ now we get all variable's list, and types of them (For simple numeric variables we get value also)
List
}
CheckGroup
</lang>
 
 
=={{header|Maple}}==
Anonymous user