1.4  Example: Data definition for self-referential data

;; A List-of-Auto is either
;;   - the empty list, or
;;   - (cons a loa) where a is an Auto and loa is a List-of-Auto

;; Examples:
(define mt-loa empty)
(define loa1 (cons auto1 mt-loa))
(define loa2 (cons (make-auto "Audi" 15 10) loa1))
(define loa3 (cons auto2 loa2))

;; A NeLoP (Non-empty List of Posn is either
;;   - (cons Posn empty)
;;   - (cons p lop) where p is a Posn and lop is a NeLoP

;; Examples:
(define nelop1 (cons p1 empty))
(define nelop2 (cons p2 nelop1))
(define nelop3 (cons (make-posn 30 50) nelop2))

;; Test the data construction:
(equal? loa1 (cons (make-auto "Ford" 15 20) empty))
(equal? loa3 (cons (make-auto "VW" 12 15) loa2))

(equal? nelop1 (cons (make-posn 10 20) empty))
(equal? nelop3 (cons (make-posn 30 50)
                     (cons (make-posn 30 20)
                           nelop1)))

;; Selectors for cons lists
(equal? auto1 (first loa1))
(equal? loa2 (rest loa3))

(equal? p1 (first nelop1))
(equal? (make-posn 30 50) (first nelop3))
(equal? nelop1 (rest nelop2))