define-struct
functions
(define-struct pt_cart (x y))
defines ...
One constructor make-pt_cart that can be used like
(define origin (make-pt_cart 0 0)) (define apoint2 (make-pt_cart 5 7))
A constructor constructs one of the indicated compound things, here a pt_cart, when given as many arguments as needed, here two.
Thus, the corresponding data definition is as follows:
A pt_cart is a (make-pt_cart x y), where x
and y are numbers.
Two selectors pt_cart-x and pt_cart-y that can be used like
(pt_cart-x apoint2) (pt_cart-y origin)
A selector selects the relevant piece of information from the compound thing, e.g., the "x" component of a pt_cart.
Selectors are also called destructors or accessors.
(Not mentioned in class...) One predicate pt_cart? that can be used like
(pt_cart? origin) (pt_cart? 3) (pt_cart? (make-point2 3 8))
A predicate determines whether or not its one argument is of the right form, here a pt_cart. Why would we use it? We'll see...