Skip to content

Commit 5b84346

Browse files
committed
Bug fix in lambda labeling.
1 parent 781c1e2 commit 5b84346

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

www/notes/loot/syntax.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
[`(if ,e0 ,e1 ,e2) (append (λs e0) (λs e1) (λs e2))]
7575
[`(+ ,e0 ,e1) (append (λs e0) (λs e1))]
7676
[`(let ((,x ,e0)) ,e1) (append (λs e0) (λs e1))]
77-
[`(letrec ,bs ,e0) (append (map second bs) (λs e0))]
77+
[`(letrec ,bs ,e0) (append (apply append (map (compose λs second) bs)) (λs e0))]
7878
[`(λ ,xs ,l ,e0) (cons e (λs e0))]
7979
[`(,e . ,es) (append (λs e) (apply append (map λs es)))]))
8080

www/notes/loot/test/compile.rkt

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,45 @@
8989
(+ n (tri (sub1 n)))))))
9090
10))
9191
56)
92-
92+
93+
(check-equal?
94+
(run
95+
'(begin (define (map f ls)
96+
(if (empty? ls)
97+
'()
98+
(cons (f (car ls)) (map f (cdr ls)))))
99+
100+
(map (λ (f) (f 0))
101+
(cons (λ (x) (add1 x))
102+
(cons (λ (x) (sub1 x))
103+
'())))))
104+
'(1 -1))
105+
106+
(check-equal?
107+
(run
108+
'(begin (define (map f ls)
109+
(letrec ((mapper (λ (ls)
110+
(if (empty? ls)
111+
'()
112+
(cons (f (car ls)) (mapper (cdr ls)))))))
113+
(mapper ls)))
114+
(map (λ (f) (f 0))
115+
(cons (λ (x) (add1 x))
116+
(cons (λ (x) (sub1 x))
117+
'())))))
118+
'(1 -1))
119+
120+
(check-equal?
121+
(run
122+
'(begin (define (map f ls)
123+
(begin (define (mapper ls)
124+
(if (empty? ls)
125+
'()
126+
(cons (f (car ls)) (mapper (cdr ls)))))
127+
(mapper ls)))
128+
(map (λ (f) (f 0))
129+
(cons (λ (x) (add1 x))
130+
(cons (λ (x) (sub1 x))
131+
'())))))
132+
'(1 -1))
93133

0 commit comments

Comments
 (0)