It is sometimes handy to define a new structure which is just like an existing structure except for having an additional slot or two.
For example, recall our example structure type
[ 'person 'name 'age 'sex | ]defstruct
and suppose that we wish to define a new
saint which is just
person except for having an
extra field in which to count miracles,
which we will initialize to two, that
being the qualifying number for a saint:
[ 'saint :include 'person 'miracles :initval 2 | ]defstruct
Now we can do
Stack: [ :name "Nick" :age 3042 :sex nil :miracles 10 | ]make-saint --> nick Stack: nick Stack: #<a saint> ls :name "Nick" :age 3042 :sex nil :miracles 10 Stack: nick person? Stack: t pop nick saint? Stack: t pop nick person-name Stack: "Nick" pop nick saint-miracles Stack: 10 pop nick.name Stack: "Nick" pop nick.miracles Stack: 10
Note that all the old access and predicate functions
person still work on type
In general, you can use a saint anywhere you can use
a person, you just have the extra field of miracles
:include only one structure in a
given structure definition -- remember, structures
are intended to be simple, cheap datastructures!
For fancy stuff, you need objects and generic
Go to the first, previous, next, last section, table of contents.