Null object: Difference between revisions

(Added Wren)
Line 1,151:
A pointer to a copy of group (as float group) is actually a pointer to group.
 
Pointers to groups can be point to an emptyNull Group, assigning a 0& value (a long type)
 
 
<lang M2000 Interpreter>
class something {
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
}
class alfa as something {
CheckGroup
x=10, y=20
}
a->alfa()
Print a is type alfa = true
Print a is type something = true
a->0&
Print a is type null = true
\\ beta is a named object, is static
group beta {
type: something, alfa
x=10, y=20
}
Print beta is type alfa = true
Print beta is type something = true
\\ now a is a pointer as a weak reference to beta
a->beta
print a is type alfa = true
print a is type something = true
a=pointer() ' same as a->0&
Print a is type null = true
\\ now a is a pointer of a copy of beta
a->(beta)
print a is type alfa = true
print a is type something = true
a=pointer() ' same as a->0&
Print a is type null = true
</lang>
 
404

edits