RosettaCodeData/Task/Call-an-object-method/M2000-Interpreter/call-an-object-method.m2000

49 lines
1.1 KiB
Plaintext

Module CheckIt {
\\ A class definition is a function which return a Group
\\ We can make groups and we can alter them using Group statement
\\ Groups may have other groups inside
Group Alfa {
Private:
myvalue=100
Public:
Group SetValue {
Set (x) {
Link parent myvalue to m
m<=x
}
}
Module MyMethod {
Read x
Print x*.myvalue
}
}
Alfa.MyMethod 5 '500
Alfa.MyMethod %x=200 ' 20000
\\ we can copy Alfa to Z
Z=Alfa
Z.MyMethod 5
Z.SetValue=300
Z.MyMethod 5 ' 1500
Alfa.MyMethod 5 ' 500
Dim A(10)
A(3)=Z
A(3).MyMethod 5 '1500
A(3).SetValue=200
A(3).MyMethod 5 '1000
\\ get a pointer of group in A(3)
k->A(3)
k=>SetValue=100
A(3).MyMethod 5 '500
\\ k get pointer to Alfa
k->Alfa
k=>SetValue=500
Alfa.MyMethod 5 '2500
k->Z
k=>MyMethod 5 ' 1500
Z.SetValue=100
k=>MyMethod 5 ' 500
}
Checkit