Skip to content

Commit

Permalink
crook
Browse files Browse the repository at this point in the history
  • Loading branch information
dvanhorn committed Dec 5, 2024
1 parent 066b56f commit 1c69a5a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
16 changes: 16 additions & 0 deletions iniquity-plus/env.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#lang racket
(provide lookup ext)

;; Env Variable -> Answer
(define (lookup env x)
(match env
['() 'err]
[(cons (list y i) env)
(match (symbol=? x y)
[#t i]
[#f (lookup env x)])]))

;; Env Variable Value -> Value
(define (ext r x i)
(cons (list x i) r))

13 changes: 1 addition & 12 deletions iniquity-plus/interp.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(provide interp-env)
(require "ast.rkt")
(require "interp-prim.rkt")
(require "env.rkt")

;; type Value =
;; | Integer
Expand Down Expand Up @@ -142,15 +143,3 @@
(cons (list x y)
(zip xs ys))]))

;; Env Id -> Value
(define (lookup r x)
(match r
[(cons (list y val) r)
(if (symbol=? x y)
val
(lookup r x))]))

;; Env Id Value -> Env
(define (ext r x v)
(cons (list x v) r))

16 changes: 16 additions & 0 deletions knock-plus/env.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#lang racket
(provide lookup ext)

;; Env Variable -> Answer
(define (lookup env x)
(match env
['() 'err]
[(cons (list y i) env)
(match (symbol=? x y)
[#t i]
[#f (lookup env x)])]))

;; Env Variable Value -> Value
(define (ext r x i)
(cons (list x i) r))

13 changes: 1 addition & 12 deletions knock-plus/interp.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(provide interp-match-pat)
(require "ast.rkt")
(require "interp-prim.rkt")
(require "env.rkt")

;; type Value =
;; | Integer
Expand Down Expand Up @@ -167,15 +168,3 @@
(cons (list x y)
(zip xs ys))]))

;; Env Id -> Value
(define (lookup r x)
(match r
[(cons (list y val) r)
(if (symbol=? x y)
val
(lookup r x))]))

;; Env Id Value -> Env
(define (ext r x v)
(cons (list x v) r))

0 comments on commit 1c69a5a

Please sign in to comment.