Go to the first, previous, next, last section, table of contents.


Default Slot Values

Particularly if a structure has many slots, and the value of some are usually the same for each instance, we may prefer to have the value of a slot default to the appropriate value on creation, saving us from having to repetitively explicitly specify these values.

For example, sailboats are occasionally dismasted or lose a rudder, but most sailboats most of the time have both mast and rudder, and we might wish Muq to assume this except when told otherwise.

Stack:
[ 'sailboat
  'name       :initval "Windward Passage"
  'has-mast   :initval t
  'has-rudder :initval t
| ]defstruct

Now any sailboat created will start out with the given values in its three slots unless we explicitly say otherwise:

Stack:
[ | ]make-sailboat --> myboat
Stack: 
myboat
Stack: #<a sailboat>
ls
:name	"Windward Passage"
:has-mast	t
:has-rudder	t
Stack:
[ :name "Leaky Sieve"
  :has-mast nil
  :has-rudder nil
| ]make-sailboat --> yourboat
Stack:
yourboat ls
:name	"Leaky Sieve"
:has-mast	nil
:has-rudder	nil


Go to the first, previous, next, last section, table of contents.