Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion www/notes/loot/syntax.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
[`(if ,e0 ,e1 ,e2) (append (λs e0) (λs e1) (λs e2))]
[`(+ ,e0 ,e1) (append (λs e0) (λs e1))]
[`(let ((,x ,e0)) ,e1) (append (λs e0) (λs e1))]
[`(letrec ,bs ,e0) (append (map second bs) (λs e0))]
[`(letrec ,bs ,e0) (append (apply append (map (compose λs second) bs)) (λs e0))]
[`(λ ,xs ,l ,e0) (cons e (λs e0))]
[`(,e . ,es) (append (λs e) (apply append (map λs es)))]))

Expand Down
42 changes: 41 additions & 1 deletion www/notes/loot/test/compile.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,45 @@
(+ n (tri (sub1 n)))))))
10))
56)


(check-equal?
(run
'(begin (define (map f ls)
(if (empty? ls)
'()
(cons (f (car ls)) (map f (cdr ls)))))

(map (λ (f) (f 0))
(cons (λ (x) (add1 x))
(cons (λ (x) (sub1 x))
'())))))
'(1 -1))

(check-equal?
(run
'(begin (define (map f ls)
(letrec ((mapper (λ (ls)
(if (empty? ls)
'()
(cons (f (car ls)) (mapper (cdr ls)))))))
(mapper ls)))
(map (λ (f) (f 0))
(cons (λ (x) (add1 x))
(cons (λ (x) (sub1 x))
'())))))
'(1 -1))

(check-equal?
(run
'(begin (define (map f ls)
(begin (define (mapper ls)
(if (empty? ls)
'()
(cons (f (car ls)) (mapper (cdr ls)))))
(mapper ls)))
(map (λ (f) (f 0))
(cons (λ (x) (add1 x))
(cons (λ (x) (sub1 x))
'())))))
'(1 -1))