Commit f12969c4 authored by Matt's avatar Matt

Added some ver marks

parent 869aeae1
......@@ -94,6 +94,7 @@
;; Func Expr
; (make-func-expr [Id] [Expr] [Environment|#f])
;>>>Q6
(define-struct func-expr (id body env) #:transparent)
;; Func Apply
......@@ -207,7 +208,7 @@
[body (parse! scnr)]
[_ (func-pop! scnr "}")]
}
(make-func-expr param-id body #f)))
(make-func-expr param-id body #f))) ;>>>Q6
(define func-pop! (curry check-pop! 'parse-partial-func-expr))
; parse-func-apply-expr! : scnr -> func-apply-expr
......@@ -258,7 +259,7 @@
[(let-expr? exp) (eval-let-expr exp env)]
[(func-expr? exp) (eval-func-expr exp env)]
[(func-apply-expr? exp) (eval-func-apply-expr exp env)]
[(id? exp) (lookup env exp)]
[(id? exp) (lookup env exp)] ;>>>Q6
[else (error 'eval "unknown internal format?!: ~v" exp)]))
; lookup : env, id -> value
......@@ -266,6 +267,7 @@
; If the value is a function, before returning it update it's
; closure to contain a reference from the identifier we found it
; under to itself (enables recursion).
;>>>Q6
(define (lookup env id)
(maybe-bind-closure
(hash-ref env id (λ () (error 'eval "Unbound Id ~v" id)))
......@@ -316,6 +318,7 @@
; Evaluates the value subexpression using the provided environment,
; then evaluates the body expression with the identifier bound to
; the result of the value expression.
;>>>Q5
(define (eval-let-expr lexpr env)
(eval (let-expr-body lexpr)
(hash-set env
......@@ -325,6 +328,7 @@
; eval-func-expr : func-expr, environment -> value
; Evaluating a function expression should return that function
; expression with its closure set to the given environment
;>>>Q6
(define (eval-func-expr fexpr env)
(make-func-expr (func-expr-id fexpr)
(func-expr-body fexpr)
......@@ -332,6 +336,7 @@
; eval-func-apply-expr : func-apply-expr, environment -> value
; Evaluate a function application using the given environment
;>>>Q5
(define (eval-func-apply-expr faexpr env)
(let {[f (func-or-err faexpr env)]
}
......
......@@ -114,7 +114,7 @@
("fact" (string->expr "(x) -> {x}")))))
24)
;; Demonstrates dynamic scope
;; Demonstrates dynamic scope (or lack thereof)
(define addM-str "say m be 100
in say addM be (x) -> {(x add m)}
in (say m be 5 in <addM @ 3> matey
......@@ -125,7 +125,7 @@ matey")
(define addM (string->expr addM-str))
(check-equal? (eval addM (mih))
206)
206) ;>>>Q6 - not 15
(check-equal? (eval addM (mih '(("n" 15))))
206)
(check-equal? (eval addM (mih '(("m" 10)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment