Next: 3.3 Traits
Up: 3 The Slate World
Previous: 3.1 Overall Organization
Contents
Index
Subsections
Slate defines several subtle variations on the core behavior of objects:
- Root
- The "root"
object, upon which all the very basic methods of slot manipulation
are defined.
- Oddball
- The branch of Root
representing non-cloneable objects. These include built-in 'constants'
such as the Booleans, as well as literals (value-objects)
such as Characters and Symbols. Note that Oddball
itself defines a clone method, but
that method will only work once, in that you can clone Oddball
but not objects made by cloning Oddball.
- Nil
- Nil is an Oddball
representing "no-object".
- Derivable
- Derivable
objects respond to derive, which
means they can be readily extended.
- Cloneable
- Cloneable
objects are derivables that can be cloned.
- Method
- A Cloneable object
with attributes for supporting execution of blocks and holding compiled
code and its attributes.
- Identity
- ==
returns whether the two arguments are identical, i.e. the same object,
and ~== is its negation. Value-equality (= and
its negation ~=) defaults to this.
- Printing
- print
returns a printed (string) representation of the object. printOn:
places the result of printing onto a designated Stream.
This should be overridden for clarity.
- Delegation-testing
- isReally:
returns whether the first object has the second (or its traits object
if it is not a Trait) as one of its delegated objects, directly
or indirectly.
- Kind-testing
- is:
returns whether the first object has the same kind as the second object,
or some derived kind from the second object's kind. By default, is:
is isReally:; overrides can allow the user to adapt or abuse
this notion where delegation isn't appropriate but kind-similarity
still should hold. isSameAs:
answers whether the arguments have the same traits object.
- Hashing
- A quick way to sort by object value that
makes searching collections faster is the hash
method, which by default hashes on the object's identity (available
separately as identityHash),
essentially by its birth address in memory. What's more important
about hashing is that this is how value-equality
is established for collections; if an object type overrides =,
it must also override the hash method's algorithm so that
a = b
a hash = b hash.
- Cloning
- The clone
method is fundamental for Slate objects. It creates and returns a
new object identical in slot names and values to the argument object,
but with a new unique identity. As such, it has a very specific meaning
and should only be used that way.
- Copying
- The copy
method makes a value-equal (=) object from the argument and
returns the new object. This should be overridden as necessary where
= is overridden. The default case is to clone the original
object.
- Conversion/coercion
- the as:
protocol provides default conversion methods between types of objects
in Slate. Some primitive types, such as Number, override
this. The as: method has a default implementation on root
objects: if no converter is found or if the objects are not of the
same type, the failure will raise a condition. Precisely, the behavior
of a as: b is to produce an object based on a
which is as much like b as possible.
- Slot-enumeration
- For
each object, the Symbols naming its slots and delegate slots
can be accessed and iterated over, using the accessors slotNames
and delegateNames, which
work with the symbol names of the slots, or the iterators slotsDo:
and delegatesDo:, which iterate
over the stored values themselves.
There are various Oddballs in the system, and they
are non-cloneable in general. However, Oddball itself may be cloned,
for extension purposes.
Next: 3.3 Traits
Up: 3 The Slate World
Previous: 3.1 Overall Organization
Contents
Index
Brian Rice
2004-10-30