my_basic
my_basic copied to clipboard
Errors with a list of objects
I experimented with lists of object instances:
' Define an object class
class Object
var myadjective = "UNINITIALIZED"
def Describe(s)
myadjective = s
enddef
def Write()
print "I'm an ", myadjective, " object!";
enddef
endclass
print "Object List Test";;
' Create a list of object instances
Obj1 = new(Object)
Obj1.Describe("awesome")
Obj2 = new(Object)
Obj2.Describe("ugly")
ObjectList1 = List(Obj1, Obj2)
Obj1 = Nil
Obj2 = Nil
for X in ObjectList1
X.Write()
next
' Create another list of object instances
Obj3 = new(Object)
Obj3.Describe("unfathomable")
Obj4 = new(Object)
Obj4.Describe("ordinary")
ObjectList2 = List(Obj3, new(Object))
Obj3 = Nil
Obj4 = Nil
for X in ObjectList2
X.Write()
next
' Try to create a third list of object instances
ObjectList3 = List(new(Object), new(Object))
Here is the output from running the program:
Object List Test
I'm an awesome object!
I'm an ugly object!
I'm an unfathomable object!
I'm an ordinary object!
Error:
Ln 53, Col 35
Code 28, Abort Code 3
Message: Colon expected.
At line 42 it executes, but the second item in the list is Obj4, instead of an uninitialized fifth object instance. At line 53 it fails.
@paladin-t curious about the status of this issue.