CS135 Lecture Notes - Lecture 4: Type System
Document Summary
Structures permit the bundling of several values into one. Constructor function make-posn has contract: ;; make-posn: num num posn. Selector functions posn-x and posn-y has contracts: ;; posn-x: posn num, ;; posn-y: posn num. Ex. (define mypoint (make-posn 8 1): (posn-x mypoint) 8, (posn-y mypoint) 1. An expression such as (make-posn 8 1) is considered a value. The expression (make-posn (+ 4 4) ( 3 2)) would be rewritten to yield (make-posn 8 1) Dynamic typing types are associated with values, not with constants or parameters. Static typing does not allow values that do not match constants or parameter types. Data definitions human-readable comments not enforced by the machine: ;; a posn is a (make-posn num num) If posn wasn"t built in, we could define it: (define-struct posn (x y)) Define-struct special form has arguments: a structure name (posn, a list of field names in parenthesis. The posn? predicate tests if its argument is a posn.