Skip to content

Commit 58a5b62

Browse files
committed
use bash to do run examples
1 parent 70f6cb7 commit 58a5b62

24 files changed

+175
-430
lines changed

examples/bool.test.lisp.out

Whitespace-only changes.

examples/cons.test.lisp.out

Whitespace-only changes.

examples/factorial-half.lisp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
(import zero? add mul sub1 "nat-church.lisp")
2-
(import zero one two three four "nat-church.lisp")
3-
(import if true false "bool.lisp")
1+
(import zero? mul sub1 "nat-church.lisp")
2+
(import one "nat-church.lisp")
3+
(import if "bool.lisp")
4+
5+
(define factorial (factorial-half factorial-half))
46

57
(define (factorial-half self n)
68
(if (zero? n)
79
one
810
(mul n (self self (sub1 n)))))
9-
10-
;; test readback of functions
11-
12-
factorial-half
13-
14-
(define factorial (factorial-half factorial-half))
15-
16-
(assert-equal (factorial zero) one)
17-
(assert-equal (factorial one) one)
18-
(assert-equal (factorial two) two)
19-
(assert-equal (factorial three) (mul three two))
20-
(assert-equal (factorial four) (mul four (mul three two)))

examples/factorial-half.test.lisp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(import zero? add mul sub1 "nat-church.lisp")
2+
(import zero one two three four "nat-church.lisp")
3+
(import if true false "bool.lisp")
4+
5+
(import factorial-half factorial "factorial-half.lisp")
6+
7+
factorial-half
8+
9+
(assert-equal (factorial zero) one)
10+
(assert-equal (factorial one) one)
11+
(assert-equal (factorial two) two)
12+
(assert-equal (factorial three) (mul three two))
13+
(assert-equal (factorial four) (mul four (mul three two)))

examples/factorial-wrap.lisp

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,13 @@
1-
(import zero? add mul sub1 "nat-church.lisp")
2-
(import zero one two three four "nat-church.lisp")
3-
(import if true false "bool.lisp")
4-
(import Y turing "fixpoint.lisp")
1+
(import zero? mul sub1 "nat-church.lisp")
2+
(import one "nat-church.lisp")
3+
(import if "bool.lisp")
4+
(import Y "fixpoint.lisp")
5+
6+
(define factorial (Y factorial-wrap))
57

68
(define factorial-wrap
79
(lambda (factorial)
810
(lambda (n)
911
(if (zero? n)
1012
one
1113
(mul n (factorial (sub1 n)))))))
12-
13-
;; test readback of functions
14-
15-
factorial-wrap
16-
17-
;; test equivalence of functions
18-
19-
(assert-equal
20-
(lambda (factorial)
21-
(factorial-wrap
22-
(factorial-wrap
23-
(factorial-wrap
24-
factorial))))
25-
(lambda (factorial)
26-
(lambda (n)
27-
(if (zero? n)
28-
one
29-
(mul
30-
n
31-
((lambda (n)
32-
(if (zero? n)
33-
one
34-
(mul
35-
n
36-
((lambda (n)
37-
(if (zero? n)
38-
one
39-
(mul
40-
n
41-
(factorial
42-
(sub1 n)))))
43-
(sub1 n)))))
44-
(sub1 n)))))))
45-
46-
(assert-equal ((Y factorial-wrap) zero) one)
47-
(assert-equal ((Y factorial-wrap) one) one)
48-
(assert-equal ((Y factorial-wrap) two) two)
49-
(assert-equal ((Y factorial-wrap) three) (mul three two))
50-
(assert-equal ((Y factorial-wrap) four) (mul four (mul three two)))
51-
52-
(assert-equal ((turing factorial-wrap) zero) one)
53-
(assert-equal ((turing factorial-wrap) one) one)
54-
(assert-equal ((turing factorial-wrap) two) two)
55-
(assert-equal ((turing factorial-wrap) three) (mul three two))
56-
(assert-equal ((turing factorial-wrap) four) (mul four (mul three two)))
57-
58-
(define factorial (Y factorial-wrap))
59-
60-
(assert-equal (factorial zero) one)
61-
(assert-equal (factorial one) one)
62-
(assert-equal (factorial two) two)
63-
(assert-equal (factorial three) (mul three two))
64-
(assert-equal (factorial four) (mul four (mul three two)))

examples/factorial-wrap.test.lisp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
(import zero? add mul sub1 "nat-church.lisp")
2+
(import zero one two three four "nat-church.lisp")
3+
(import if true false "bool.lisp")
4+
(import Y turing "fixpoint.lisp")
5+
6+
(import factorial-wrap factorial "factorial-wrap.lisp")
7+
8+
;; test readback of functions
9+
10+
factorial-wrap
11+
12+
;; test equivalence of functions
13+
14+
(assert-equal
15+
(lambda (factorial)
16+
(factorial-wrap
17+
(factorial-wrap
18+
(factorial-wrap
19+
factorial))))
20+
(lambda (factorial)
21+
(lambda (n)
22+
(if (zero? n)
23+
one
24+
(mul
25+
n
26+
((lambda (n)
27+
(if (zero? n)
28+
one
29+
(mul
30+
n
31+
((lambda (n)
32+
(if (zero? n)
33+
one
34+
(mul
35+
n
36+
(factorial
37+
(sub1 n)))))
38+
(sub1 n)))))
39+
(sub1 n)))))))
40+
41+
(assert-equal ((Y factorial-wrap) zero) one)
42+
(assert-equal ((Y factorial-wrap) one) one)
43+
(assert-equal ((Y factorial-wrap) two) two)
44+
(assert-equal ((Y factorial-wrap) three) (mul three two))
45+
(assert-equal ((Y factorial-wrap) four) (mul four (mul three two)))
46+
47+
(assert-equal ((turing factorial-wrap) zero) one)
48+
(assert-equal ((turing factorial-wrap) one) one)
49+
(assert-equal ((turing factorial-wrap) two) two)
50+
(assert-equal ((turing factorial-wrap) three) (mul three two))
51+
(assert-equal ((turing factorial-wrap) four) (mul four (mul three two)))
52+
53+
(assert-equal (factorial zero) one)
54+
(assert-equal (factorial one) one)
55+
(assert-equal (factorial two) two)
56+
(assert-equal (factorial three) (mul three two))
57+
(assert-equal (factorial four) (mul four (mul three two)))

examples/factorial.lisp

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,8 @@
1-
(import zero? add mul sub1 "nat-church.lisp")
2-
(import zero one two three four "nat-church.lisp")
3-
(import if true false "bool.lisp")
1+
(import zero? mul sub1 "nat-church.lisp")
2+
(import one "nat-church.lisp")
3+
(import if "bool.lisp")
44

55
(define (factorial n)
66
(if (zero? n)
77
one
88
(mul n (factorial (sub1 n)))))
9-
10-
(assert-equal (factorial zero) one)
11-
(assert-equal (factorial one) one)
12-
(assert-equal (factorial two) two)
13-
(assert-equal (factorial three) (mul three two))
14-
(assert-equal (factorial four) (mul four (mul three two)))
15-
16-
;; test equivalence between recursive functions
17-
18-
(assert-same factorial factorial)
19-
(assert-equal factorial factorial)
20-
21-
(assert-not-same factorial (lambda (x) (factorial x)))
22-
(assert-equal factorial (lambda (y) (factorial y)))
23-
(assert-equal factorial (lambda (x) (factorial x)))
24-
(assert-equal (lambda (x) (factorial x)) (lambda (y) (factorial y)))
25-
26-
;; test readback of recursive functions
27-
28-
factorial

examples/factorial.lisp.out

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)