Let's define a structure type person
:
Stack: [ 'person 'name 'age 'sex | ]defstruct Stack:
We may now create structures of this type:
Stack: [ :name "Pat" :age 21 :sex t | ]make-person --> pat Stack: pat Stack: #<a person> ls :name "Pat" :age 21 :sex t
Structure slots may be accessed using the usual path notation:
Stack: pat.name Stack: "Pat" pop "Kim" --> pat.name Stack: pat.name Stack: "Kim"
Structure slots may also be accessed using
functions which ]defstruct
defined
for the purpose:
Stack: pat person-name Stack: "Kim" pop pat "Pat" set-person-name Stack: pat person-name Stack: "Pat"
Finally, ]defstruct
has defined a
a predicate person?
and assertion
is-a-person
which may be
used to test whether a value is a person:
Stack: 2.3 person? Stack: nil pop pat person? Stack: t pop pat is-a-person Stack:
That's all you need to know about structs for most routine applications!
However, ]defstruct
has many more tricks up
its sleeve, which can be very handy on occasion.
We'll cover some of them in the following sections;
For full details, See section `]defstruct' in Muf Reference.
Go to the first, previous, next, last section, table of contents.