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 | (define-struct cons (frst rst)) |
No define-struct needed. |
; A list-of-symbols is one of ; - empty ; - (make-cons symbol list-of-symbols) |
; A list-of-symbols is one of ; - empty ; - (cons symbol list-of-symbols) |
|
(On paper, we'd also draw an arrow highlighting the self-reference of "list-of-symbols".) | ||
Constructors | empty make-cons |
empty cons |
empty is technically a constructor, even
though it is a constant. |
||
Selectors | cons-frst cons-rst |
first rest |
Predicates | empty? cons? |
empty? cons? |