Mirrors

  • The mechanism by which the programming environment can reflect on the system.

  • Created with _Mirror on a reflectee
    (or reflect: reflectee).

  • Can access slot names, contents, and annotations.

  • Also provide access to programming primitives.

Mirrors

How does the programming environment discover the structure of an object, if there are no classes? In particular:

  • How are slot names found?
  • How is the source of a method obtained?
  • Indeed, how is a reference to a method obtained, given the evaluation rules?
Bear in mind that the user interface must be able to deal with any object, including empty objects (no slots at all), and objects which are incomplete (e.g., under construction).

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"

[ Previous ] [ Index ] [ Next ]