Skip to content

Commit e49e939

Browse files
committed
fix examples/list.scm
1 parent 2fa0c3e commit e49e939

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
fix `examples/list.scm`
21
review diary

examples/list.scm

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
;; (define nil
2-
;; (lambda (nil-case ::-case)
3-
;; nil-case))
4-
5-
;; (define (:: head tail)
6-
;; (lambda (nil-case ::-case)
7-
;; (::-case head tail
8-
;; (tail nil-case ::-case))))
9-
10-
;; (define (rec-List target nil-case ::-case)
11-
;; (target nil-case ::-case))
12-
13-
;; (import zero add1 "./nat-church.scm")
14-
15-
;; (define (length l)
16-
;; (rec-List l
17-
;; zero
18-
;; (lambda (head target almost)
19-
;; (add1 almost))))
20-
21-
;; (import true "./boolean.scm")
22-
23-
;; (assert-equal (length nil) zero)
24-
;; (assert-equal (length (:: true nil)) (add1 zero))
25-
;; (assert-equal (length (:: true (:: true nil))) (add1 (add1 zero)))
26-
27-
;; (define (append left right)
28-
;; (rec-List left
29-
;; right
30-
;; (lambda (head target almost)
31-
;; (:: head almost))))
32-
33-
;; (assert-equal (append nil nil) nil)
34-
;; (assert-equal (append nil (:: true nil)) (:: true nil))
35-
;; (assert-equal (append (:: true nil) nil) (:: true nil))
36-
;; (assert-equal (append (:: true nil) (:: true nil)) (:: true (:: true nil)))
37-
;; (assert-equal (append (:: true (:: true nil))
38-
;; (:: true (:: true nil)))
39-
;; (:: true (:: true (:: true (:: true nil)))))
1+
(define null
2+
(lambda (null-case cons-case)
3+
null-case))
4+
5+
(define (cons head tail)
6+
(lambda (null-case cons-case)
7+
(cons-case head tail
8+
(tail null-case cons-case))))
9+
10+
(define (rec-List target null-case cons-case)
11+
(target null-case cons-case))
12+
13+
(import zero add1 "./nat-church.scm")
14+
15+
(define (length l)
16+
(rec-List l
17+
zero
18+
(lambda (head target almost)
19+
(add1 almost))))
20+
21+
(import true "./boolean.scm")
22+
23+
(assert-equal (length null) zero)
24+
(assert-equal (length (cons true null)) (add1 zero))
25+
(assert-equal (length (cons true (cons true null))) (add1 (add1 zero)))
26+
27+
(define (append left right)
28+
(rec-List left
29+
right
30+
(lambda (head target almost)
31+
(cons head almost))))
32+
33+
(assert-equal (append null null) null)
34+
(assert-equal (append null (cons true null)) (cons true null))
35+
(assert-equal (append (cons true null) null) (cons true null))
36+
(assert-equal (append (cons true null) (cons true null)) (cons true (cons true null)))
37+
(assert-equal (append (cons true (cons true null))
38+
(cons true (cons true null)))
39+
(cons true (cons true (cons true (cons true null)))))

0 commit comments

Comments
 (0)