|
MirrorsHow does the programming environment discover the structure of an object, if there are no classes? In particular:
The answer is provided by special objects known as mirrors which have reflective powers (groan). A mirror can be obtained on any object using the _Mirror primitive. The subject of the mirror's scrutiny is known as its reflectee. defaultBehavior defines a method, reflect: obj, which returns a mirror on obj. Look in traits mirrors abstractMirror for all the possibilities.
reflectee "return the object being inspected" size "number of slots in the reflectee" names "a vector of slot names" at: slotName PutContents: mirror "Change the contents of slotName to be the reflectee of mirror" parentsDo: aBlock "Iterate over the parent slots" addSlot: slotMirror "Add a slot" addSlots: mirror "Add all the slots from the mirror's reflectee" addSlotsIfAbsent: mirror define: mirror "Make the reflectee of the receiver look like the reflectee of the argument" |