Prev Up Next

We can have some initializations done during the definition of the structure itself, instead of per instance. Thus, we could postulate that leaf-shape and leaf-color are by default frond and green respectively. We can always override these defaults by providing explicit initialization in the make-tree call, or by using a field modifier after the structure instance has been created:

(defstruct tree height girth age
                (leaf-shape 'frond)
                (leaf-color 'green))

(define palm (make-tree 'height 60))

(tree.height palm) 
=> 60

(tree.leaf-shape palm) 
=> frond

(define plantain 
  (make-tree 'height 7
             'leaf-shape 'sheet))

(tree.height plantain) 
=> 7

(tree.leaf-shape plantain) 
=> sheet

(tree.leaf-color plantain) 
=> green

Prev Up Next

Log in or register to write something here or to contact authors.