Skip to content

Commit 4423e42

Browse files
committed
c4 6
1 parent 4a02752 commit 4423e42

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/eval/c4_6.scm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
; in eval.scm

src/eval/eval.scm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
((cond? exp) (seck-eval (cond->if exp) env))
3737
((and? exp) (seck-eval (and->if exp) env))
3838
((or? exp) (seck-eval (or->if exp) env))
39+
((let? exp) (seck-eval (let->combination exp) env))
3940
((application? exp)
4041
(seck-apply (seck-eval (operator exp) env)
4142
(list-of-values (operand exp) env)))
@@ -375,6 +376,18 @@
375376
(define (lambda-body exp)
376377
(cddr exp))
377378

379+
; @(let)
380+
(define (let? exp)
381+
(tagged-list? exp 'let))
382+
383+
(define (let->combination exp)
384+
(let ((var-bindings (cadr exp))
385+
(body (cddr exp)))
386+
(let ((vars (map car var-bindings))
387+
(values (map cadr var-bindings)))
388+
(cons (cons 'lambda
389+
(cons vars body))
390+
values))))
378391

379392
; @(application)
380393
(define application? pair?)
@@ -437,4 +450,9 @@
437450
1))
438451
(assert (equal? (seck-eval '(op2 2 2) new-env)
439452
4))
453+
(assert (equal? (seck-eval '(let ((a 3)
454+
(b 4))
455+
(cons a b))
456+
new-env)
457+
(cons 3 4)))
440458
))

0 commit comments

Comments
 (0)