Using lists is so common that Scheme has list functions built-in, except using some different names from those used when we introduced them. (Labbies: Note that students have seen both versions.)
| In-class introduction | For use from now on | |
|---|---|---|
| Data definition |
; A list-of-symbols is one of ; - empty ; - (make-los f r) ; where f is a symbol, ; and r is a list-of-symbols. |
; A list-of-symbols is one of ; - empty ; - (cons f r) ; where f is a symbol, ; and r is a list-of-symbols. |
| (On paper, we'd also draw an arrow highlighting the self-reference of "list-of-symbols".) | ||
(define-struct los (f r)) |
No define-struct needed. |
|
| Constructors | emptymake-los |
emptycons |
empty is technically a constructor, even
though it is a constant. |
||
| Selectors | los-flos-r |
firstrest |
| Predicates | empty?los? |
empty?cons? |
(Although students saw the shorthand (list 'a 'short 'example)
in class, we'll strongly emphasize the above recursive definition for now.)