Common Lisp/Reference/defstruct

From Wikibooks, open books for an open world
Jump to: navigation, search

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


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[edit]


  1. Fundamentals of CLOS by Nick Levine, Ravenbrook Limited, 2003-07-15