Skip to content

Commit 4a02752

Browse files
committed
c4 5
1 parent ddb1e63 commit 4a02752

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/eval/c4_5.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: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
(let ((found (car ret))
6161
(value (cadr ret)))
6262
(cond (found value)
63-
((null? (base-env))
63+
((empty-env? (base-env))
6464
(error 'lookup "variable not defined" var))
6565
(else
6666
(((base-env) 'lookup) var))))))
@@ -104,6 +104,8 @@
104104
((env 'insert) var value))
105105

106106
(define the-empty-env '())
107+
(define (empty-env? env)
108+
(null? env))
107109

108110
; @(expression)
109111

@@ -130,6 +132,14 @@
130132
(else
131133
(make-begin seq))))
132134

135+
(define (sequence->exp-2 predicate actions)
136+
(if (eq? (car actions) '=>)
137+
; transforms to '(cadr (= a 3)) if predicate is (= a 3)
138+
; Note predicate will evaluated twice in the conditions!
139+
(list (cadr actions)
140+
predicate)
141+
(sequence->exp actions)))
142+
133143
(define (make-begin seq)
134144
(cons 'begin seq))
135145

@@ -315,13 +325,15 @@
315325
'false
316326
(let ((first (cond-firstmatch matches))
317327
(rest (cond-restmatches matches)))
318-
(if (cond-elsematch? first)
319-
(if (null? rest)
320-
(make-if 'true (sequence->exp (cond-match-actions first)))
321-
(error 'cond "else is not last match"))
322-
(make-if (cond-match-predicate first)
323-
(sequence->exp (cond-match-actions first))
324-
(expand rest))))))
328+
(cond ((cond-elsematch? first) ;else
329+
(if (null? rest)
330+
(make-if 'true (sequence->exp (cond-match-actions first)))
331+
(error 'cond "else is not last match")))
332+
(else ; the other conditions
333+
(make-if (cond-match-predicate first)
334+
(sequence->exp-2 (cond-match-predicate first)
335+
(cond-match-actions first))
336+
(expand rest)))))))
325337
(expand (cdr exp)))
326338

327339
; @(and/or)

0 commit comments

Comments
 (0)