CS135 Lecture Notes - Lecture 4: Type System

84 views2 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents