Common Lisp/Reference/defstruct

< Common Lisp < Reference

The defstruct construct declares a new user-defined data type which has a fixed number of named components. It also creates structure constructor.

Example

The following example[1] declares a Lisp structure with the symbol point and three slots referenced by the symbols x, y, and z. Here constructor is named make-point.

(defstruct point x y z) ; define structure

(defvar my-point) ; define var 

(setf my-point (make-point :x 3 :y 4 :z 12)) ;  set value of slots of var 

(point-x my-point) ; acces to slots

See also

References

  1. Fundamentals of CLOS by Nick Levine, Ravenbrook Limited, 2003-07-15
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.