Last modified on 9 November 2011, at 08:26

Io Programming/Pitfalls

Subtle Io pitfallsEdit

Object initializationEdit

A := Object clone do(
 ...
 init := method(
  ...
 )
)

Now, you can use the A object, but the A object is not yet initialized (by the init method). The init method is only called when the A object is cloned. This can for instance "bite" you if you implement your own clone method for an object.

Reading variables/slots that contains activable objectsEdit

If a variable/slot is assigned with an activable object, you need to use getSlot("varname") to get the same object. Otherwise, the object will be activated and you will get the result of the activation instead. One such activable object is a method.

For example, if you want to do some introspection, and inspect the methods of an object:

method_to_inspect := Object getSlot("asString")

# print the code of this method
getSlot("method_to_inspect") code println

# error, (Object asString), a String, doesn't understand the code message
method_to_inspect code println

BugsEdit

Self Referential PrototypeEdit

Trying to set the prototype of an object to the object being contained by that object like this:

A := Object clone do(
 B := Object clone
 B appendProto(A)
)

Can cause IoVM to die with Segmentation Fault. You need to replace that code with something that looks like this:

A := Object clone
A do(
 B := Object clone
 B appendProto(A)
)

A is known to the parser but has no sane value in memory in the first use, so it tries to append invalid memory to the list of prototypes. In the second form the slot is both known to the parser and also filled with a valid object, so it works.