I would like to create a table for each instance of a class. How best to do it. If i define "makeTable" inside a defclass it gives me an error.
defclass( pinInfo () ( ( pinName @initarg pinName ) ( pinType @initarg pinType ) ( netName @initarg netName )
PinTable = makeTable("aTable1" 0)
I get an error when i define it like this "*Error* slotValue: no such slot - PinTable.
You can't just stick arbitrary code inside a class definition - you could either do it with an @initform:
defclass(pinInfo () ( (pinName @initarg pinName) (pinType @initarg pinType) (netName @initarg netName) (pinTable @initform makeTable("aTable1" 0)) ))
> a=makeInstance('pinInfo)stdobj@0x8564018> a->pinTabletable:aTable1> a->pinTable["hello"]=2323> a->pinTable->??("hello" 23)
Or you could define an initializeInstance method:
defclass(pinInfo () ( (pinName @initarg pinName) (pinType @initarg pinType) (netName @initarg netName) (pinTable) ))
defmethod(initializeInstance @after ((obj pinInfo)) obj->pinTable=makeTable("aTable1" 0))
Note that the second approach only works in IC615 onwards. You could use a non-@after method, but then you'd have to make sure you call callNextMethod() appropriately to ensure that any parent objects have a chance to initialize too. The @after directive tells it to call all the other @after methods, least-specific first.The intention for initializeInstance is to handle complex initialization of objects which can't be coded via the @initform (e.g. interdependencies of the arguments).