;;;;;;;;;;;;;;;;; chapter 4 ;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;; Type Checking ;;;;;;;;;;;;;;;;;;;;; (load "4-2.scm") ;; literal numbers and booleans pass (type-check "1") (type-check "true") ;; unbound variables do not pass (type-check "x") ;; primitive expressions on right number/type of args pass (type-check "+(2,3)") (type-check "add1(0)") (type-check "zero?(5)") ;; wrong number/type of arguments do not pass (type-check "+(2,true)") (type-check "+(1,2,3)") ;; conditionals with boolean test exp and same then/else exp types pass (type-check "if zero?(5) then 4 else 5") (type-check "if if zero?(5) then false else true then 1 else 2") ;; wrong test or different types in then/else exps do not pass (type-check "if 0 then 4 else 5") (type-check "if zero?(5) then 4 else true") ;; well-formed procedures pass (type-check "proc(int x) x") (type-check "proc(int x, bool y) x") (type-check "proc(int x, bool y) y") (type-check "proc(int x, bool y) if y then x else add1(x)") ; curry (type-check "proc((int * int -> int) f) proc(int x) proc(int y) (f x y)") ;; ill-formed procedures do not pass (type-check "proc((int * int -> int) f) proc(int x) proc(int y) (f x)") (type-check "proc(int x, bool y) if x then y else add1(x)") ;; procedure applications with right argument types/number pass (type-check "(proc(int x, int y) -(x,y) 4 3)" ) ;; procedure applications with wrong argument types/number do not pass (type-check "(proc(int x, int y) -(x,y) 4 true)" ) (type-check "(proc(int x, int y) -(x,y) 4 5 6)" )