Examining an Object’s Structure

So far we have explored the treasures of the global symbol table; the various means of addressing an object through the use of its vocabulary, its symbolic name, or its object reference tag; and the messages involved in exploring an object’s “family” lineage, its ancestors, parents, descendants, and children.

 

Now it’s time to explore the structure of the object itself. Proteus takes advantage of many of the TADS 3 reflection features in order to give us a glimpse into an object’s structure during runtime.

 

What Do We Mean by Structure?

The getInherStrucList() message can be sent to any Object class object. It will return a list consisting of the following elements:

 

[[object [ directlyDefinedPropertyList ]], …]

 

The method iterates over the entire inheritance hierarchy of the object, and is capable of producing a prodigious list, indeed. The following is an example of the partial list produced from me.getInherStrucList():

 

[

[me, [&location, &pendingCommand, &antecedentTable, &objRefTag]],

[Actor, [&name, &itNom, &theNamePossNoun, &itIsContraction, &conjugateRegularVerb, &itPossNoun, &pronounSelector, &verbEndingS, &itVerb, &itReflexive, &verbEndingEs, &theName, &thatObj, &verbWas, &thatNom, &travelerName, &aNameObj, &verbToBe, &verbEndingIes, &theNamePossAdj, &itPossAdj, &itIs, &theNameObj, &aName, &conjugationSelector, &verbToHave, &itObj, &objRefTag]],

. . .

]

 

The full list would continue for several pages.

 

The method takes a variable argument list. The valid signatures are:

 

 

If suppress is true then object / property list sub-elements are not added to the list when the property list is empty.

 

The callback function func should be of the form func(obj, prop) that returns either true or nil. If the function returns true the object / property sub-element is added to the list, otherwise it is not.

Structure Classes

The message Actor.getInherSuperclassList() produces a list consisting of some 12 objects.

 

 

It can be seen from this list that none of the objects occur more than once in the structure list. Even though the method iterates down and across the entire inheritance hierarchy, only unique objects are added to the list in the order that they are encountered in the traversal. The objects appearing as numbers are unnamed internals and indicate that the named objects preceding in the list have been modified by the modify keyword.

 

The method takes a variable argument list. The valid signatures are:

 

 

The callback function func should be of the form func(obj, propList) that returns either true or nil. If the function returns true the object is added to the list, otherwise it is not.

Structure Properties

The getInherPropList() message take the same approach as the getInherSuperclassList() message, producing a list of the properties that the object defines or inherits throughout the inheritance hierarchy. The list contains only one occurrence of each property, when the property is encountered in the inheritance traversal.

 

The method takes a variable argument list. The valid signatures are:

 

 

The callback function func should be of the form func(obj, prop) that returns either true or nil. If the function returns true the property is added to the list, otherwise it is not.

 

State Structure

State is reflected by an object’s attributes, behavior by an object’s methods. Together attributes and methods provide the state and behavior that make up an object’s representation of whatever it is modeling. The message getInherStateStrucList() returns a structure list composed only of the objects / properties that reflect an object’s state.

 

For instance, the following partial list is returned from me.getInherStateStrucList():

 

[

[me, [&location, &pendingCommand, &antecedentTable, &objRefTag]],

[Actor, []],

[tads#45a ( 4b0), [&travelerPreCond, &isListedAboardVehicle, &isLikelyCommandTarget, &nextRunTime, &preCondDobjAskFor, &preCondDobjTalkTo, &bulkCapacity, &maxSingleBulk, &scheduleOrder, &isListedInInventory, &preCondDobjKiss, &takeFromNotInMessage, &actorNotifyList, &smelllikeSenses, &sightlikeSenses, &inventoryLister, &nextHoldingIndex, &pcReferralPerson, &scopeSenses, &holdingDescInventoryLister, &isActor, &issueCommandsSynchronously, &hearinglikeSenses, &followables_, &posture, &wearingLister, &holdingDescWearingLister, &weightCapacity, &communicationSenses]]

       . . .

]

 

The list returns only the attributes for each trait of the object that would be reflected by self.(prop). So if more than one trait defines an attribute only the one for which self.(prop) would reflect the value is chosen. This is called the object’s defined property and is discussed further below.

 

Where an object in the structure list does define any properties, in this instance attributes, the property list is empty. Such is the case with Actor, which is a modification of Actor, and deriving from tads#45a ( 4b0).

 

The method takes a variable argument list. The valid signatures are:

 

 

If suppress is true then object / propList sub-elements are not added to the list when the propList is empty.

 

The callback function func should be of the form func(obj, prop) that returns either true or nil. If the function returns true the object / property sub-element is added to the list, otherwise it is not.

 

An Object’s Defined Structure

An object’s defined property is the key to returning an object’s defined structure. Suppose we have the following object definitions:

 

myObject: Thing

{

       myAttribute = ‘hello’

}

 

myChildObject: myObject

{

       myAttribute = ‘goodbye’

}

 

anotherObject: myChildObject

{

}

 

Now what is returned by the message anotherObject.myAttribute? Traversing the inheritance hierarchy we come to myAttribute first defined in myChildObject. Thus myChildObject is the defining trait for the property myAttribute for object anotherObject.

 

Thus getInherDefStrucList() would return a list that we partially display below:

 

[

[anotherObject, []],

[myChildObject, [&myAttribute]],

[myObject, []],

. . .

]

 

This list agrees with our intuitive assessment.

 

Retrieving an object’s defined structure is so useful that Proteus provides the message getInherDefPropList().  This message returns a list of those properties that are meet the self.(prop) test we mentioned earlier.

 

The method takes a variable argument list. The valid signatures are:

 

 

If suppress is true then object / propList sub-elements are not added to the list when the propList is empty.

 

The callback function func should be of the form func(obj, prop) that returns either true or nil. If the function returns true the object / property sub-element is added to the list, otherwise it is not.

 

 

This file is part of the TADS 3 Proteus Library Extension

Copyright © 2001-2004 Kevin Forchione. All rights reserved.