Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My solution to exercise 3.34 #19

Open
ShorterThanDijkstra opened this issue Nov 3, 2022 · 0 comments
Open

My solution to exercise 3.34 #19

ShorterThanDijkstra opened this issue Nov 3, 2022 · 0 comments
Assignees

Comments

@ShorterThanDijkstra
Copy link

; empty-env : () → Env
(define empty-env
(lambda ()
(lambda (op)
(cond
[(eqv? op 'envrionment?) #t]
[(eqv? op 'empty?) #t]
[(eqv? op 'search)
(lambda (search-var)
(eopl:error 'empty-env))]
[else (eopl:error 'empty-env)]))))

; extend-env : Var × SchemeVal × Env → Env
(define extend-env
(lambda (saved-var saved-val saved-env)
(lambda (op)
(cond
[(eqv? op 'envrionment?) #t]
[(eqv? op 'empty?) #f]
[(eqv? op 'search)
(lambda (search-var)
(if (eqv? search-var saved-var)
saved-val
(apply-env saved-env search-var)))]
[else (eopl:error 'extend-env)]))))

; extend-env : Var × Var × Expression × Env → Env
(define extend-env-rec
(lambda (proc-name bound-var proc-body saved-env)
(letrec ((env
(lambda (op)
(cond
[(eqv? op 'envrionment?) #t]
[(eqv? op 'empty?) #f]
[(eqv? op 'search)
(lambda (search-var)
(if (eqv? search-var proc-name)
(proc-val (procedure bound-var proc-body env))
(apply-env saved-env search-var)))]
[else (eopl:error 'extend-env-rec)]))))
env)))

; apply-env : Env × Var → SchemeVal
(define apply-env
(lambda (env search-var)
((env 'search) search-var)))

(define environment?
(lambda (env)
(if (procedure? env)
(env 'envrionment?)
#f)))

@ShorterThanDijkstra ShorterThanDijkstra changed the title My solution of exercise 3.34 My solution to exercise 3.34 Nov 3, 2022
@chenyukang chenyukang self-assigned this Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants