Commits

Roshan Mathews  committed 5835803

Init commit, after finishing mutations (upto 8.1 in book.)

  • Participants

Comments (0)

Files changed (10)

+.*~$

File ArithC-p.rkt

+#lang plai
+
+(define-type ArithC
+  [numC (n number?)]
+  [plusC (l ArithC?) (r ArithC?)]
+  [multC (l ArithC?) (r ArithC?)])
+
+(define (parse e)
+  (cond
+    [(number? e) (numC e)]
+    [(list? e)
+     (case (first e)
+       [(+) (plusC (parse (second e)) (parse (third e)))]
+       [(*) (multC (parse (second e)) (parse (third e)))])]))
+
+(define (interp a)
+  (type-case ArithC a
+    [numC (n) n]
+    [plusC (l r) (+ (interp l) (interp r))]
+    [multC (l r) (* (interp l) (interp r))]))
+
+(define-type ArithS
+  [numS (n number?)]
+  [plusS (l ArithS?) (r ArithS?)]
+  [bminusS (l ArithS?) (r ArithS?)]
+  [multS (l ArithS?) (r ArithS?)])
+
+(define (desugar as)
+  (type-case ArithS as
+    [numS (n) (numC n)]
+    [plusS (l r) (plusC (desugar l)
+                        (desugar r))]
+    [multS (l r) (multC (desugar l)
+                        (desugar r))]
+    [bminusS (l r) (plusC (desugar l)
+                      (multC (numC -1) (desugar r)))]))
+

File ArithC-pt.rkt

+#lang plai-typed
+
+(define-type ArithC
+  [numC (n : number)]
+  [plusC (l : ArithC) (r : ArithC)]
+  [multC (l : ArithC) (r : ArithC)])
+
+(define (parse s) : ArithC
+  (cond 
+    [(s-exp-number? s) (numC (s-exp->number s))]
+    [(s-exp-list? s)
+     (let ([sl (s-exp->list s)])
+       (case (s-exp->symbol (first sl))
+         [(+) (plusC (parse (second sl)) (parse (third sl)))]
+         [(*) (multC (parse (second sl)) (parse (third sl)))]))]
+    [else (error 'parse "invalid list input")]))
+
+(define (interp [a : ArithC]) : number
+  (type-case ArithC a
+    [numC (n) n]
+    [plusC (l r) (+ (interp l) (interp r))]
+    [multC (l r) (* (interp l) (interp r))]))
+
+; tests
+(print-only-errors #t)
+
+(test (interp (parse '(+ 1 2))) 3)
+(test (interp (parse '(* 3 4))) 12)
+(test (interp (parse '(* (+ 1 2)
+                         (* (+ 3 4)
+                            (+ 5 6)))))
+      231)

File ArithS-pt.rkt

+#lang plai-typed
+
+;; Core Language
+
+(define-type ArithC
+  [numC (n : number)]
+  [plusC (l : ArithC) (r : ArithC)]
+  [multC (l : ArithC) (r : ArithC)])
+
+(define (interp [a : ArithC]) : number
+  (type-case ArithC a
+    [numC (n) n]
+    [plusC (l r) (+ (interp l) (interp r))]
+    [multC (l r) (* (interp l) (interp r))]))
+
+;; Surface Language
+
+(define-type ArithS
+  [numS (n : number)]
+  [plusS (l : ArithS) (r : ArithS)]
+  [bminusS (l : ArithS) (r : ArithS)]
+  [multS (l : ArithS) (r : ArithS)])
+
+(define (parse s) : ArithS
+  (cond 
+    [(s-exp-number? s) (numS (s-exp->number s))]
+    [(s-exp-list? s)
+     (let ([sl (s-exp->list s)])
+       (case (s-exp->symbol (first sl))
+         [(+) (plusS (parse (second sl)) (parse (third sl)))]
+         [(*) (multS (parse (second sl)) (parse (third sl)))]
+         [(-) (bminusS (parse (second sl)) (parse (third sl)))]))]
+    [else (error 'parse "invalid list input")]))
+
+(define (desugar [as : ArithS]) : ArithC
+  (type-case ArithS as
+    [numS (n) (numC n)]
+    [plusS (l r) (plusC (desugar l) (desugar r))]
+    [bminusS (l r) (plusC (desugar l) 
+                         (multC (numC -1) 
+                                (desugar r)))]
+    [multS (l r) (multC (desugar l) (desugar r))]))
+
+                         
+                         

File Conditional-pt.rkt

+#lang plai-typed
+
+;; Core Language
+
+(define-type ArithC
+  [numC (n : number)]
+  [plusC (l : ArithC) (r : ArithC)]
+  [multC (l : ArithC) (r : ArithC)])
+
+(define (interp [a : ArithC]) : number
+  (type-case ArithC a
+    [numC (n) n]
+    [plusC (l r) (+ (interp l) (interp r))]
+    [multC (l r) (* (interp l) (interp r))]))
+
+;; Surface Language
+
+(define-type ArithS
+  [numS (n : number)]
+  [plusS (l : ArithS) (r : ArithS)]
+  [bminusS (l : ArithS) (r : ArithS)]
+  [multS (l : ArithS) (r : ArithS)]
+  [ifS (predicate : number) (true : ArithS) (false : ArithS)])
+
+(define (parse s) : ArithS
+  (cond 
+    [(s-exp-number? s) (numS (s-exp->number s))]
+    [(s-exp-list? s)
+     (let ([sl (s-exp->list s)])
+       (case (s-exp->symbol (first sl))
+         [(+) (plusS (parse (second sl)) (parse (third sl)))]
+         [(*) (multS (parse (second sl)) (parse (third sl)))]
+         [(-) (bminusS (parse (second sl)) (parse (third sl)))]
+         [(if) (ifS (s-exp->number (second sl))
+                    (parse (third sl)) 
+                    (parse (fourth sl)))]))]
+    [else (error 'parse "invalid list input")]))
+
+(define (desugar [as : ArithS]) : ArithC
+  (type-case ArithS as
+    [numS (n) (numC n)]
+    [plusS (l r) (plusC (desugar l) (desugar r))]
+    [bminusS (l r) (plusC (desugar l) 
+                          (multC (numC -1) 
+                                 (desugar r)))]
+    [multS (l r) (multC (desugar l) (desugar r))]
+    [ifS (p t f) (if (not (= p 0)) 
+                     (desugar t)
+                     (desugar f))]))
+#lang plai-typed
+
+(define-type Binding
+  [bind (name : symbol) (val : number)])
+
+(define-type-alias Env (listof Binding))
+(define mt-env empty)
+(define extend-env cons)
+
+(define (interp [expr : ExprC] [env : Env] [fds : (listof FunDefC)]) : number
+  (type-case ExprC expr
+    [numC (n) n]
+    [idC (s) (lookup s env)]
+    [appC (f a) (local ([define fd (get-fundef f fds)])
+                  (interp (fdC-body fd)
+                          (extend-env (bind (fdC-arg fd)
+                                            (interp a env fds))
+                                      mt-env)
+                          fds))]
+    [plusC (l r) (+ (interp l env fds)
+                    (interp r env fds))]
+    [multC (l r) (* (interp l env fds)
+                    (interp r env fds))]))
+
+(define (lookup [s : symbol] [env : Env])
+  (cond
+    [(empty? env) (error 'lookup "unbound symbol")]
+    [(symbol=? s (bind-name (first env))) (bind-val (first env))]
+    [else (lookup s (rest env))]))
+
+(define-type FunDefC
+  [fdC (name : symbol)
+       (arg : symbol)
+       (body : ExprC)])
+
+(define-type ExprC
+  [numC (n : number)]
+  [idC (s : symbol)]
+  [appC (fun : symbol) (arg : ExprC)]
+  [plusC (l : ExprC) (r : ExprC)]
+  [multC (l : ExprC) (r : ExprC)])
+
+(define (get-fundef [f : symbol] [fds : (listof FunDefC)]) : FunDefC
+  (cond 
+    ([empty? fds] (error 'get-fundef "missing function"))
+    ([symbol=? f (fdC-name (first fds))] (first fds))
+    (else (get-fundef f (rest fds)))))
+
+; Tests
+(print-only-errors #f)
+(test (interp 
+       (appC 'double (plusC (numC 1) (numC 2)))
+       mt-env
+       [list (fdC 'double 'x (plusC (idC 'x) (idC 'x)))])
+      6)
+
+(test (interp (plusC (numC 10) (appC 'const5 (numC 10)))
+              mt-env
+              (list (fdC 'const5 '_ (numC 5))))
+      15)
+
+(test (interp (plusC (numC 10) (appC 'double (plusC (numC 1) (numC 2))))
+              mt-env
+              (list (fdC 'double 'x (plusC (idC 'x) (idC 'x)))))
+      16)
+
+(test (interp (plusC (numC 10) (appC 'quadruple (plusC (numC 1) (numC 2))))
+              mt-env
+              (list (fdC 'quadruple 'x (appC 'double (appC 'double (idC 'x))))
+                    (fdC 'double 'x (plusC (idC 'x) (idC 'x)))))
+      22)

File ExprC-pt.rkt

+#reader(lib"read.ss""wxme")WXME0108 ## 
+#|
+   This file uses the GRacket editor format.
+   Open this file in DrRacket version 5.3 or later to read it.
+
+   Most likely, it was created by saving a program in DrRacket,
+   and it probably contains a program with non-text elements
+   (such as images or comment boxes).
+
+            http://racket-lang.org/
+|#
+ 29 7 #"wxtext\0"
+3 1 6 #"wxtab\0"
+1 1 8 #"wximage\0"
+2 0 8 #"wxmedia\0"
+4 1 34 #"(lib \"syntax-browser.ss\" \"mrlib\")\0"
+1 0 16 #"drscheme:number\0"
+3 0 44 #"(lib \"number-snip.ss\" \"drscheme\" \"private\")\0"
+1 0 36 #"(lib \"comment-snip.ss\" \"framework\")\0"
+1 0 93
+(
+ #"((lib \"collapsed-snipclass.ss\" \"framework\") (lib \"collapsed-sni"
+ #"pclass-wxme.ss\" \"framework\"))\0"
+) 0 0 43 #"(lib \"collapsed-snipclass.ss\" \"framework\")\0"
+0 0 19 #"drscheme:sexp-snip\0"
+0 0 36 #"(lib \"cache-image-snip.ss\" \"mrlib\")\0"
+1 0 68
+(
+ #"((lib \"image-core.ss\" \"mrlib\") (lib \"image-core-wxme.rkt\" \"mr"
+ #"lib\"))\0"
+) 1 0 29 #"drscheme:bindings-snipclass%\0"
+1 0 88
+(
+ #"((lib \"pict-snip.rkt\" \"drracket\" \"private\") (lib \"pict-snip.r"
+ #"kt\" \"drracket\" \"private\"))\0"
+) 0 0 33 #"(lib \"bullet-snip.ss\" \"browser\")\0"
+0 0 25 #"(lib \"matrix.ss\" \"htdp\")\0"
+1 0 22 #"drscheme:lambda-snip%\0"
+1 0 57
+#"(lib \"hrule-snip.rkt\" \"macro-debugger\" \"syntax-browser\")\0"
+1 0 26 #"drscheme:pict-value-snip%\0"
+0 0 45 #"(lib \"image-snipr.ss\" \"slideshow\" \"private\")\0"
+1 0 38 #"(lib \"pict-snipclass.ss\" \"slideshow\")\0"
+2 0 55 #"(lib \"vertical-separator-snip.ss\" \"stepper\" \"private\")\0"
+1 0 18 #"drscheme:xml-snip\0"
+1 0 31 #"(lib \"xml-snipclass.ss\" \"xml\")\0"
+1 0 21 #"drscheme:scheme-snip\0"
+2 0 34 #"(lib \"scheme-snipclass.ss\" \"xml\")\0"
+1 0 10 #"text-box%\0"
+1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0"
+1 0 1 6 #"wxloc\0"
+          0 0 58 0 1 #"\0"
+0 75 1 #"\0"
+0 12 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9
+#"Standard\0"
+0 75 7 #"Monaco\0"
+0 12 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24
+#"framework:default-color\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 15
+#"text:ports out\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 15 #"text:ports err\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 17
+#"text:ports value\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 27 #"Matching Parenthesis Style\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1
+-1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:symbol\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 38
+#"framework:syntax-color:scheme:keyword\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2
+38 #"framework:syntax-color:scheme:comment\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 37
+#"framework:syntax-color:scheme:string\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 39
+#"framework:syntax-color:scheme:constant\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 42
+#"framework:syntax-color:scheme:parenthesis\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:error\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 36
+#"framework:syntax-color:scheme:other\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2
+38 #"drracket:check-syntax:lexically-bound\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 178 34 34 0 0 0 -1 -1 2 28
+#"drracket:check-syntax:set!d\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 178 34 34 0 0 0 -1 -1 2 37
+#"drracket:check-syntax:unused-require\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 36
+#"drracket:check-syntax:free-variable\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 31
+#"drracket:check-syntax:imported\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 47
+#"drracket:check-syntax:my-obligation-style-pref\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 178 34 34 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 116 0 0 0 0 -1 -1 2 50
+#"drracket:check-syntax:their-obligation-style-pref\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 116 0 0 0 0 -1 -1 2 48
+#"drracket:check-syntax:unk-obligation-style-pref\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 142 28 0 0 0 -1 -1 2
+49 #"drracket:check-syntax:both-obligation-style-pref\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 139 142 28 0 0 0 -1 -1 2
+26 #"plt:htdp:test-coverage-on\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 2 27
+#"plt:htdp:test-coverage-off\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1
+#"\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 4 #"XML\0"
+0 70 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 37
+#"plt:module-language:test-coverage-on\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 34 139 34 0 0 0 -1 -1 2 1
+#"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 176 48 96 0 0 0 -1 -1 2 38
+#"plt:module-language:test-coverage-off\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 176 48 96 0 0 0 -1 -1 4 1
+#"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1
+-1 4 1 #"\0"
+0 71 1 #"\0"
+1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1
+-1 4 1 #"\0"
+0 -1 1 #"\0"
+1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 255 255 0 -1 -1 2
+1 #"\0"
+0 -1 1 #"\0"
+1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 200 0 0 0 0 0 -1 -1 0 1
+#"\0"
+0 -1 1 #"\0"
+0 13 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1 2 1 #"\0"
+0 -1 1 #"\0"
+0 13 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0
+-1 -1           0 541 0 26 3 16 #"#lang plai-typed"
+0 0 22 29 1 #"\n"
+0 0 22 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 11 #"define-type"
+0 0 22 3 1 #" "
+0 0 14 3 7 #"FunDefC"
+0 0 22 29 1 #"\n"
+0 0 22 3 3 #"  ["
+0 0 14 3 3 #"fdC"
+0 0 22 3 2 #" ("
+0 0 14 3 4 #"name"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 6 #"symbol"
+0 0 22 3 1 #")"
+0 0 22 29 1 #"\n"
+0 0 22 3 8 #"       ("
+0 0 14 3 3 #"arg"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 6 #"symbol"
+0 0 22 3 1 #")"
+0 0 22 29 1 #"\n"
+0 0 22 3 8 #"       ("
+0 0 14 3 4 #"body"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 3 3 #")])"
+0 0 22 29 1 #"\n"
+0 0 22 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 11 #"define-type"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 29 1 #"\n"
+0 0 22 3 3 #"  ["
+0 0 14 3 4 #"numC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"n"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 6 #"number"
+0 0 22 3 2 #")]"
+0 0 22 29 1 #"\n"
+0 0 22 3 3 #"  ["
+0 0 14 3 3 #"idC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"s"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 6 #"symbol"
+0 0 22 3 2 #")]"
+0 0 22 29 1 #"\n"
+0 0 22 3 3 #"  ["
+0 0 14 3 4 #"appC"
+0 0 22 3 2 #" ("
+0 0 14 3 3 #"fun"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 6 #"symbol"
+0 0 22 3 3 #") ("
+0 0 14 3 3 #"arg"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 3 2 #")]"
+0 0 22 29 1 #"\n"
+0 0 22 3 3 #"  ["
+0 0 14 3 5 #"plusC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"l"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 3 3 #") ("
+0 0 14 3 1 #"r"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 3 2 #")]"
+0 0 22 29 1 #"\n"
+0 0 22 3 3 #"  ["
+0 0 14 3 5 #"multC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"l"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 3 3 #") ("
+0 0 14 3 1 #"r"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 3 3 #")])"
+0 0 22 29 1 #"\n"
+0 0 22 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 22 3 2 #" ("
+0 0 14 3 6 #"interp"
+0 0 22 3 3 #"  ["
+0 0 14 3 1 #"e"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 3 3 #"] ["
+0 0 14 3 3 #"fds"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 2 #" ("
+0 0 14 3 6 #"listof"
+0 0 22 3 1 #" "
+0 0 14 3 7 #"FunDefC"
+0 0 22 3 4 #")]) "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 6 #"number"
+0 0 22 29 1 #"\n"
+0 0 22 3 3 #"  ("
+0 0 15 3 9 #"type-case"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"e"
+0 0 22 29 1 #"\n"
+0 0 22 3 5 #"    ["
+0 0 14 3 4 #"numC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"n"
+0 0 22 3 2 #") "
+0 0 14 3 1 #"n"
+0 0 22 3 1 #"]"
+0 0 22 29 1 #"\n"
+0 0 22 3 5 #"    ["
+0 0 14 3 3 #"idC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"_"
+0 0 22 3 3 #") ("
+0 0 14 3 5 #"error"
+0 0 22 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 6 #"interp"
+0 0 22 3 1 #" "
+0 0 19 3 20 #"\"shouldn't get here\""
+0 0 22 3 2 #")]"
+0 0 22 29 1 #"\n"
+0 0 22 3 5 #"    ["
+0 0 14 3 4 #"appC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"f"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"a"
+0 0 22 3 3 #") ("
+0 0 15 3 5 #"local"
+0 0 22 3 3 #" (["
+0 0 15 3 6 #"define"
+0 0 22 3 1 #" "
+0 0 14 3 2 #"fd"
+0 0 22 3 2 #" ("
+0 0 14 3 10 #"get-fundef"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"f"
+0 0 22 3 1 #" "
+0 0 14 3 3 #"fds"
+0 0 22 3 3 #")])"
+0 0 22 29 1 #"\n"
+0 0 22 3 19 #"                  ("
+0 0 14 3 6 #"interp"
+0 0 22 3 2 #" ("
+0 0 14 3 5 #"subst"
+0 0 22 3 2 #" ("
+0 0 14 3 6 #"interp"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"a"
+0 0 22 3 1 #" "
+0 0 14 3 3 #"fds"
+0 0 22 3 1 #")"
+0 0 22 29 1 #"\n"
+0 0 22 3 34 #"                                 ("
+0 0 14 3 7 #"fdC-arg"
+0 0 22 3 1 #" "
+0 0 14 3 2 #"fd"
+0 0 22 3 1 #")"
+0 0 22 29 1 #"\n"
+0 0 22 3 34 #"                                 ("
+0 0 14 3 8 #"fdC-body"
+0 0 22 3 1 #" "
+0 0 14 3 2 #"fd"
+0 0 22 3 2 #"))"
+0 0 22 29 1 #"\n"
+0 0 22 3 26 #"                          "
+0 0 14 3 3 #"fds"
+0 0 22 3 3 #"))]"
+0 0 22 29 1 #"\n"
+0 0 22 3 5 #"    ["
+0 0 14 3 5 #"plusC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"l"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"r"
+0 0 22 3 3 #") ("
+0 0 14 3 1 #"+"
+0 0 22 3 2 #" ("
+0 0 14 3 6 #"interp"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"l"
+0 0 22 3 1 #" "
+0 0 14 3 3 #"fds"
+0 0 22 3 3 #") ("
+0 0 14 3 6 #"interp"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"r"
+0 0 22 3 1 #" "
+0 0 14 3 3 #"fds"
+0 0 22 3 3 #"))]"
+0 0 22 29 1 #"\n"
+0 0 22 3 5 #"    ["
+0 0 14 3 5 #"multC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"l"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"r"
+0 0 22 3 3 #") ("
+0 0 14 3 1 #"*"
+0 0 22 3 2 #" ("
+0 0 14 3 6 #"interp"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"l"
+0 0 22 3 1 #" "
+0 0 14 3 3 #"fds"
+0 0 22 3 3 #") ("
+0 0 14 3 6 #"interp"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"r"
+0 0 22 3 1 #" "
+0 0 14 3 3 #"fds"
+0 0 22 3 5 #"))]))"
+0 0 22 29 1 #"\n"
+0 0 22 29 1 #"\n"
+0 7         865 4           0 0           0 143 0 17 3 41
+#"; subst : ExprC * symbol * ExprC -> ExprC"
+0 0 22 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 22 3 2 #" ("
+0 0 14 3 5 #"subst"
+0 0 22 3 2 #" ["
+0 0 14 3 4 #"what"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 3 3 #"] ["
+0 0 15 3 3 #"for"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 6 #"symbol"
+0 0 22 3 3 #"] ["
+0 0 14 3 2 #"in"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 3 3 #"]) "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 29 1 #"\n"
+0 0 22 3 3 #"  ("
+0 0 15 3 9 #"type-case"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 3 1 #" "
+0 0 14 3 2 #"in"
+0 0 22 29 1 #"\n"
+0 0 22 3 5 #"    ["
+0 0 14 3 4 #"numC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"n"
+0 0 22 3 2 #") "
+0 0 14 3 2 #"in"
+0 0 22 3 1 #"]"
+0 0 22 29 1 #"\n"
+0 0 22 3 5 #"    ["
+0 0 14 3 3 #"idC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"s"
+0 0 22 3 3 #") ("
+0 0 15 3 4 #"cond"
+0 0 22 3 1 #" "
+0 0 22 29 1 #"\n"
+0 0 22 3 17 #"               [("
+0 0 14 3 8 #"symbol=?"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"s"
+0 0 22 3 1 #" "
+0 0 15 3 3 #"for"
+0 0 22 3 2 #") "
+0 0 14 3 4 #"what"
+0 0 22 3 1 #"]"
+0 0 22 29 1 #"\n"
+0 0 22 3 16 #"               ["
+0 0 14 3 4 #"else"
+0 0 22 3 1 #" "
+0 0 14 3 2 #"in"
+0 0 22 3 3 #"])]"
+0 0 22 29 1 #"\n"
+0 0 22 3 5 #"    ["
+0 0 14 3 4 #"appC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"f"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"a"
+0 0 22 3 3 #") ("
+0 0 14 3 4 #"appC"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"f"
+0 0 22 3 2 #" ("
+0 0 14 3 5 #"subst"
+0 0 22 3 1 #" "
+0 0 14 3 4 #"what"
+0 0 22 3 1 #" "
+0 0 15 3 3 #"for"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"a"
+0 0 22 3 3 #"))]"
+0 0 22 29 1 #"\n"
+0 0 22 3 5 #"    ["
+0 0 14 3 5 #"plusC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"l"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"r"
+0 0 22 3 3 #") ("
+0 0 14 3 5 #"plusC"
+0 0 22 3 2 #" ("
+0 0 14 3 5 #"subst"
+0 0 22 3 1 #" "
+0 0 14 3 4 #"what"
+0 0 22 3 1 #" "
+0 0 15 3 3 #"for"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"l"
+0 0 22 3 1 #")"
+0 0 22 29 1 #"\n"
+0 0 22 3 25 #"                        ("
+0 0 14 3 5 #"subst"
+0 0 22 3 1 #" "
+0 0 14 3 4 #"what"
+0 0 22 3 1 #" "
+0 0 15 3 3 #"for"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"r"
+0 0 22 3 3 #"))]"
+0 0 22 29 1 #"\n"
+0 0 22 3 5 #"    ["
+0 0 14 3 5 #"multC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"l"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"r"
+0 0 22 3 3 #") ("
+0 0 14 3 5 #"multC"
+0 0 22 3 2 #" ("
+0 0 14 3 5 #"subst"
+0 0 22 3 1 #" "
+0 0 14 3 4 #"what"
+0 0 22 3 1 #" "
+0 0 15 3 3 #"for"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"l"
+0 0 22 3 1 #")"
+0 0 22 29 1 #"\n"
+0 0 22 3 25 #"                        ("
+0 0 14 3 5 #"subst"
+0 0 22 3 1 #" "
+0 0 14 3 4 #"what"
+0 0 22 3 1 #" "
+0 0 15 3 3 #"for"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"r"
+0 0 22 3 5 #"))]))"
+0           0 0 0 22 29 1 #"\n"
+0 0 22 29 1 #"\n"
+0 0 17 3 42 #"; subst : number * symbol * ExprC -> ExprC"
+0 0 22 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 22 3 2 #" ("
+0 0 14 3 5 #"subst"
+0 0 22 3 2 #" ["
+0 0 14 3 4 #"what"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 6 #"number"
+0 0 22 3 3 #"] ["
+0 0 15 3 3 #"for"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 6 #"symbol"
+0 0 22 3 3 #"] ["
+0 0 14 3 2 #"in"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 3 3 #"]) "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 29 1 #"\n"
+0 0 22 3 3 #"  ("
+0 0 15 3 5 #"local"
+0 0 22 3 3 #" (["
+0 0 15 3 6 #"define"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"whatC"
+0 0 22 3 2 #" ("
+0 0 14 3 4 #"numC"
+0 0 22 3 1 #" "
+0 0 14 3 4 #"what"
+0 0 22 3 3 #")])"
+0 0 22 29 1 #"\n"
+0 0 22 3 5 #"    ("
+0 0 15 3 9 #"type-case"
+0 0 22 3 1 #" "
+0 0 14 3 5 #"ExprC"
+0 0 22 3 1 #" "
+0 0 14 3 2 #"in"
+0 0 22 29 1 #"\n"
+0 0 22 3 7 #"      ["
+0 0 14 3 4 #"numC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"n"
+0 0 22 3 2 #") "
+0 0 14 3 2 #"in"
+0 0 22 3 1 #"]"
+0 0 22 29 1 #"\n"
+0 0 22 3 7 #"      ["
+0 0 14 3 3 #"idC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"s"
+0 0 22 3 3 #") ("
+0 0 15 3 4 #"cond"
+0 0 22 3 1 #" "
+0 0 22 29 1 #"\n"
+0 0 22 3 19 #"                 [("
+0 0 14 3 8 #"symbol=?"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"s"
+0 0 22 3 1 #" "
+0 0 15 3 3 #"for"
+0 0 22 3 2 #") "
+0 0 14 3 5 #"whatC"
+0 0 22 3 1 #"]"
+0 0 22 29 1 #"\n"
+0 0 22 3 18 #"                 ["
+0 0 14 3 4 #"else"
+0 0 22 3 1 #" "
+0 0 14 3 2 #"in"
+0 0 22 3 3 #"])]"
+0 0 22 29 1 #"\n"
+0 0 22 3 7 #"      ["
+0 0 14 3 4 #"appC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"f"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"a"
+0 0 22 3 3 #") ("
+0 0 14 3 4 #"appC"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"f"
+0 0 22 3 2 #" ("
+0 0 14 3 5 #"subst"
+0 0 22 3 1 #" "
+0 0 14 3 4 #"what"
+0 0 22 3 1 #" "
+0 0 15 3 3 #"for"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"a"
+0 0 22 3 3 #"))]"
+0 0 22 29 1 #"\n"
+0 0 22 3 7 #"      ["
+0 0 14 3 5 #"plusC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"l"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"r"
+0 0 22 3 3 #") ("
+0 0 14 3 5 #"plusC"
+0 0 22 3 2 #" ("
+0 0 14 3 5 #"subst"
+0 0 22 3 1 #" "
+0 0 14 3 4 #"what"
+0 0 22 3 1 #" "
+0 0 15 3 3 #"for"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"l"
+0 0 22 3 1 #")"
+0 0 22 29 1 #"\n"
+0 0 22 3 27 #"                          ("
+0 0 14 3 5 #"subst"
+0 0 22 3 1 #" "
+0 0 14 3 4 #"what"
+0 0 22 3 1 #" "
+0 0 15 3 3 #"for"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"r"
+0 0 22 3 3 #"))]"
+0 0 22 29 1 #"\n"
+0 0 22 3 7 #"      ["
+0 0 14 3 5 #"multC"
+0 0 22 3 2 #" ("
+0 0 14 3 1 #"l"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"r"
+0 0 22 3 3 #") ("
+0 0 14 3 5 #"multC"
+0 0 22 3 2 #" ("
+0 0 14 3 5 #"subst"
+0 0 22 3 1 #" "
+0 0 14 3 4 #"what"
+0 0 22 3 1 #" "
+0 0 15 3 3 #"for"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"l"
+0 0 22 3 1 #")"
+0 0 22 29 1 #"\n"
+0 0 22 3 27 #"                          ("
+0 0 14 3 5 #"subst"
+0 0 22 3 1 #" "
+0 0 14 3 4 #"what"
+0 0 22 3 1 #" "
+0 0 15 3 3 #"for"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"r"
+0 0 22 3 6 #"))])))"
+0 0 22 29 1 #"\n"
+0 0 22 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 15 3 6 #"define"
+0 0 22 3 2 #" ("
+0 0 14 3 10 #"get-fundef"
+0 0 22 3 2 #" ["
+0 0 14 3 1 #"f"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 6 #"symbol"
+0 0 22 3 3 #"] ["
+0 0 14 3 3 #"fds"
+0 0 22 3 1 #" "
+0 0 14 3 1 #":"
+0 0 22 3 2 #" ("
+0 0 14 3 6 #"listof"
+0 0 22 3 1 #" "
+0 0 14 3 7 #"FunDefC"
+0 0 22 3 4 #")]) "
+0 0 14 3 1 #":"
+0 0 22 3 1 #" "
+0 0 14 3 7 #"FunDefC"
+0 0 22 29 1 #"\n"
+0 0 22 3 3 #"  ("
+0 0 15 3 4 #"cond"
+0 0 22 3 1 #" "
+0 0 22 29 1 #"\n"
+0 0 22 3 6 #"    (["
+0 0 14 3 6 #"empty?"
+0 0 22 3 1 #" "
+0 0 14 3 3 #"fds"
+0 0 22 3 3 #"] ("
+0 0 14 3 5 #"error"
+0 0 22 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 10 #"get-fundef"
+0 0 22 3 1 #" "
+0 0 19 3 18 #"\"missing function\""
+0 0 22 3 2 #"))"
+0 0 22 29 1 #"\n"
+0 0 22 3 6 #"    (["
+0 0 14 3 8 #"symbol=?"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"f"
+0 0 22 3 2 #" ("
+0 0 14 3 8 #"fdC-name"
+0 0 22 3 2 #" ("
+0 0 14 3 5 #"first"
+0 0 22 3 1 #" "
+0 0 14 3 3 #"fds"
+0 0 22 3 5 #"))] ("
+0 0 14 3 5 #"first"
+0 0 22 3 1 #" "
+0 0 14 3 3 #"fds"
+0 0 22 3 2 #"))"
+0 0 22 29 1 #"\n"
+0 0 22 3 5 #"    ("
+0 0 14 3 4 #"else"
+0 0 22 3 2 #" ("
+0 0 14 3 10 #"get-fundef"
+0 0 22 3 1 #" "
+0 0 14 3 1 #"f"
+0 0 22 3 2 #" ("
+0 0 14 3 4 #"rest"
+0 0 22 3 1 #" "
+0 0 14 3 3 #"fds"
+0 0 22 3 5 #")))))"
+0 0 22 29 1 #"\n"
+0 0 22 29 1 #"\n"
+0 0 17 3 7 #"; Tests"
+0 0 22 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 14 3 17 #"print-only-errors"
+0 0 22 3 1 #" "
+0 0 20 3 2 #"#t"
+0 0 22 3 1 #")"
+0 0 22 29 1 #"\n"
+0 0 22 3 1 #"("
+0 0 14 3 4 #"test"
+0 0 22 3 2 #" ("
+0 0 14 3 6 #"interp"
+0 0 22 3 1 #" "
+0 0 22 29 1 #"\n"
+0 0 22 3 8 #"       ("
+0 0 14 3 4 #"appC"
+0 0 22 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 6 #"double"
+0 0 22 3 2 #" ("
+0 0 14 3 5 #"plusC"
+0 0 22 3 2 #" ("
+0 0 14 3 4 #"numC"
+0 0 22 3 1 #" "
+0 0 20 3 1 #"1"
+0 0 22 3 3 #") ("
+0 0 14 3 4 #"numC"
+0 0 22 3 1 #" "
+0 0 20 3 1 #"2"
+0 0 22 3 3 #")))"
+0 0 22 29 1 #"\n"
+0 0 22 3 8 #"       ["
+0 0 14 3 4 #"list"
+0 0 22 3 2 #" ("
+0 0 14 3 3 #"fdC"
+0 0 22 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 6 #"double"
+0 0 22 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 1 #"x"
+0 0 22 3 2 #" ("
+0 0 14 3 5 #"plusC"
+0 0 22 3 2 #" ("
+0 0 14 3 3 #"idC"
+0 0 22 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 1 #"x"
+0 0 22 3 3 #") ("
+0 0 14 3 3 #"idC"
+0 0 22 3 1 #" "
+0 0 20 3 1 #"'"
+0 0 14 3 1 #"x"
+0 0 22 3 5 #")))])"
+0 0 22 29 1 #"\n"
+0 0 22 3 6 #"      "
+0 0 20 3 1 #"6"
+0 0 22 3 1 #")"
+0 0 22 29 1 #"\n"
+0           0

File Functions-pt.rkt

+#lang plai-typed
+
+(define-type Value
+  [numV (n : number)]
+  [closV (arg : symbol) (body : ExprC) (env : Env)])
+
+(define-type ExprC
+  [numC (n : number)]
+  [idC (s : symbol)]
+  [appC (fun : ExprC) (arg : ExprC)]
+  [plusC (l : ExprC) (r : ExprC)]
+  [multC (l : ExprC) (r : ExprC)]
+  [lamC (arg : symbol) (body : ExprC)])
+
+(define (interp [expr : ExprC] [env : Env]) : Value
+  (type-case ExprC expr
+    [numC (n) (numV n)]
+    [idC (s) (lookup s env)]
+    [appC (f a) (local ([define f-value (interp f env)])
+                  (interp (closV-body f-value)
+                          (extend-env (bind (closV-arg f-value)
+                                            (interp a env))
+                                      (closV-env f-value))))]
+    [plusC (l r) (num+ (interp l env)
+                       (interp r env))]
+    [multC (l r) (num* (interp l env)
+                       (interp r env))]
+    [lamC (a b) (closV a b env)]))
+
+(define (num+ [l : Value] [r : Value]) : Value
+  (cond 
+    [(and (numV? l) (numV? r))
+     (numV (+ (numV-n l) (numV-n r)))]
+    [else
+     (error 'num+ "one argument was not a number")]))
+
+(define (num* [l : Value] [r : Value]) : Value
+  (cond 
+    [(and (numV? l) (numV? r))
+     (numV (* (numV-n l) (numV-n r)))]
+    [else
+     (error 'num* "one argument was not a number")]))
+
+; --
+
+(define-type Binding
+  [bind (name : symbol) (val : Value)])
+
+(define-type-alias Env (listof Binding))
+(define mt-env empty)
+(define extend-env cons)
+
+(define (lookup [s : symbol] [env : Env]) : Value
+  (cond
+    [(empty? env) (error 'lookup "unbound symbol")]
+    [(symbol=? s (bind-name (first env))) (bind-val (first env))]
+    [else (lookup s (rest env))]))
+
+; Tests
+(print-only-errors #t)
+(test (interp (appC (lamC 'x (plusC (idC 'x) (idC 'x))) (numC 3)) 
+              mt-env)
+      (numV 6))
+(test (interp (plusC (numC 10) (appC (lamC '_ (numC 5)) (numC 10)))
+              mt-env)
+      (numV 15))
+(test (interp (appC (lamC 'x (appC (lamC 'y (plusC (idC 'x) (idC 'y)))
+                                   (numC 4)))
+                    (numC 3))
+              mt-env)
+      (numV 7))

File MisspelledAnimal-pt.rkt

+#lang plai-typed
+
+(define-type MisspelledAnimal
+  [caml (humps : number)]
+  [yacc (height : number)])
+
+(define (good? [ma : MisspelledAnimal])
+  (type-case MisspelledAnimal ma
+    [caml (h) (>= h 2)]
+    [yacc (h) (>= h 3)]))
+
+(define ma1 (caml 2))
+(define ma2 (yacc 1.9))
+
+(print-only-errors #t)
+
+(test (good? ma1) #t)
+(test (good? ma2) #f)

File Mutating-pt.rkt

+#lang plai-typed
+
+(define-type ExprC
+  [numC (n : number)]
+  [idC (s : symbol)]
+  [appC (fun : ExprC) (arg : ExprC)]
+  [plusC (l : ExprC) (r : ExprC)]
+  [multC (l : ExprC) (r : ExprC)]
+  [lamC (arg : symbol) (body : ExprC)]
+  [boxC (arg : ExprC)]
+  [unboxC (arg : ExprC)]
+  [setboxC (b : ExprC) (v : ExprC)]
+  [seqC (b1 : ExprC) (b2 : ExprC)])
+
+(define-type Value
+  [numV (n : number)]
+  [closV (arg : symbol) (body : ExprC) (env : Env)]
+  [boxV (l : Location)])
+
+(define-type Result
+  [v*s (v : Value) (s : Store)])
+
+(define-type-alias Location number)
+
+(define-type Binding
+  [bind (name : symbol) (val : Location)])
+
+(define-type-alias Env (listof Binding))
+(define mt-env empty)
+(define extend-env cons)
+
+(define-type Storage
+  [cell (location : Location) (val : Value)])
+
+(define-type-alias Store (listof Storage))
+(define mt-store empty)
+(define override-store cons)
+
+(define (interp (expr : ExprC) (env : Env) (sto : Store)) : Result
+  (type-case ExprC expr
+    [numC (n) (v*s (numV n) sto)]
+    [idC (s) (v*s (fetch (lookup s env) sto) sto)]
+    [appC (f a) (type-case Result (interp f env sto)
+                  [v*s (v-f s-f)
+                       (type-case Result (interp a env s-f)
+                         [v*s (v-a s-a)
+                              (let ([where (new-loc)])
+                                (interp (closV-body v-f)
+                                        (extend-env (bind (closV-arg v-f)
+                                                          where)
+                                                    (closV-env v-f))
+                                        (override-store (cell where v-a)
+                                                        s-a)))])])]
+    [plusC (l r)
+           (type-case Result (interp l env sto)
+             [v*s (v-l s-l)
+                  (type-case Result (interp r env s-l)
+                    [v*s (v-r s-r)
+                         (v*s (num+ v-l v-r) s-r)])])]
+    [multC (l r)
+           (type-case Result (interp l env sto)
+             [v*s (v-l s-l)
+                  (type-case Result (interp r env s-l)
+                    [v*s (v-r s-r)
+                         (v*s (num* v-l v-r) s-r)])])]
+    [lamC (a b) (v*s (closV a b env) sto)]
+    [boxC (a)
+          (type-case Result (interp a env sto)
+            [v*s (v-a s-a)
+                 (let ([where (new-loc)])
+                   (v*s (boxV where)
+                        (override-store (cell where v-a)
+                                        s-a)))])]
+    [unboxC (a)
+            (type-case Result (interp a env sto)
+              [v*s (v-a s-a)
+                   (v*s (fetch (boxV-l v-a) s-a) s-a)])]
+    [setboxC (b v) (type-case Result (interp b env sto)
+                     [v*s (v-b s-b)
+                          (type-case Result (interp v env s-b)
+                            [v*s (v-v s-v)
+                                 (v*s v-v
+                                      (override-store 
+                                       (cell (boxV-l v-b)
+                                             v-v)
+                                       s-v))])])]
+    [seqC (b1 b2) (type-case Result (interp b1 env sto)
+                    [v*s (v-b1 s-b1) 
+                         (interp b2 env s-b1)])]))
+
+(define (num+ [l : Value] [r : Value]) : Value
+  (cond 
+    [(and (numV? l) (numV? r))
+     (numV (+ (numV-n l) (numV-n r)))]
+    [else
+     (error 'num+ "one argument was not a number")]))
+
+(define (num* [l : Value] [r : Value]) : Value
+  (cond 
+    [(and (numV? l) (numV? r))
+     (numV (* (numV-n l) (numV-n r)))]
+    [else
+     (error 'num* "one argument was not a number")]))
+
+(define (lookup [for : symbol] [env : Env]) : Location
+  (cond 
+    [(empty? env) (error 'lookup "unbound symbol")]
+    [(symbol=? for (bind-name (first env))) (bind-val (first env))]
+    [else (lookup for (rest env))]))
+
+(define (fetch [loc : Location] [sto : Store]) : Value
+  (cond
+    [(empty? sto) (error 'fetch "location not found")]
+    [(= loc (cell-location (first sto))) (cell-val (first sto))]
+    [else (fetch loc (rest sto))]))
+
+(define new-loc
+  (let ([n (box 0)])
+    (lambda () (begin
+                 (set-box! n (add1 (unbox n)))
+                 (unbox n)))))
+
+
+; Tests
+(print-only-errors #t)
+(test (v*s-v 
+       (interp (appC (lamC 'x (plusC (idC 'x) (idC 'x))) (numC 3)) 
+               mt-env mt-store))
+      (numV 6))
+(test (v*s-v 
+       (interp (plusC (numC 10) (appC (lamC '_ (numC 5)) (numC 10)))
+               mt-env mt-store))
+      (numV 15))
+(test (v*s-v 
+       (interp (appC (lamC 'x (appC (lamC 'y (plusC (idC 'x) (idC 'y)))
+                                    (numC 4)))
+                     (numC 3))
+               mt-env mt-store))
+      (numV 7))
+(test (v*s-v 
+       (interp 
+        (appC 
+         (lamC 'b
+               (seqC (seqC (setboxC (idC 'b) (plusC (numC 1)
+                                                    (unboxC (idC 'b))))
+                           (setboxC (idC 'b) (plusC (numC 1)
+                                                    (unboxC (idC 'b)))))
+                     (unboxC (idC 'b))))
+         (boxC (numC 0)))
+        mt-env mt-store))
+      (numV 2))