Scheme types
Scheme types are strong, dynamic and implicit. The standard types are as follows:
- The usual: numbers, strings, chars, booleans
- More interesting:
- symbols: Unique symbolic tokens for use in computation.
- functions: Procedures that return a value (sometimes undefined)
- lists: a series of linked cons cells. Lists are really just chains of cons cells, so many authors like to say pairs rather than lists are a basic primitive type. (There is a Scheme procedure pair? that tests whether something is a cons cell.)
- (Also, vectors and ports)
Virtually all Scheme types can be treated uniformly:
(define jumbled-list '( 12 ; number (lambda (n) (* n n)) ; function "foo" ; string #\a ; char #f ; boolean 'foo ; symbol '(a b c d) ; list )) Recall the primitive operations that apply to lists of cons cells:
- cons
- car
- cdr
Try evaluating the following, and naming the type:
(car jumbled-list) => (cdr (cdr jumbled-list)) => ((car (cdr jumbled-list)) 5) => (cons (car jumbled-list) ((cadr jumbled-list) 4)) =>