Skip to content

Commit b38f13c

Browse files
committed
prepare to remove lazy
1 parent 2bdf715 commit b38f13c

File tree

7 files changed

+35
-31
lines changed

7 files changed

+35
-31
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
prepare to remove lazy
21
remove lazy for now
32

43
`readback` handle recursive function

examples/factorial-half.lisp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
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? add mul sub1 "nat-church.lisp")
2+
;; (import zero one two three four "nat-church.lisp")
3+
;; (import if true false "bool.lisp")
44

5-
;; (claim factorial-half
6-
;; (fix (lambda (X) (-> X Nat Nat))))
5+
;; ;; (claim factorial-half
6+
;; ;; (fix (lambda (X) (-> X Nat Nat))))
77

8-
(define (factorial-half self n)
9-
(if (zero? n)
10-
one
11-
(mul n (self self (sub1 n)))))
8+
;; (define (factorial-half self n)
9+
;; (if (zero? n)
10+
;; one
11+
;; (mul n (self self (sub1 n)))))
1212

13-
factorial-half
13+
;; factorial-half
1414

15-
(define factorial (factorial-half factorial-half))
15+
;; (define factorial (factorial-half factorial-half))
1616

17-
(assert-equal (factorial zero) one)
18-
(assert-equal (factorial one) one)
19-
(assert-equal (factorial two) two)
20-
(assert-equal (factorial three) (mul three two))
21-
(assert-equal (factorial four) (mul four (mul three two)))
17+
;; (assert-equal (factorial zero) one)
18+
;; (assert-equal (factorial one) one)
19+
;; (assert-equal (factorial two) two)
20+
;; (assert-equal (factorial three) (mul three two))
21+
;; (assert-equal (factorial four) (mul four (mul three two)))

examples/factorial-half.lisp.out

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

examples/factorial-wrap.lisp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(import zero? add mul sub1 "nat-church.lisp")
22
(import zero one two three four "nat-church.lisp")
33
(import if true false "bool.lisp")
4-
(import Y turing "fix.lisp")
4+
(import Y "fix.lisp")
55

66
;; (claim factorial-wrap (-> (-> Nat Nat) (-> Nat Nat)))
77
;; (claim (Y factorial-wrap) (-> Nat Nat))
@@ -49,12 +49,6 @@ factorial-wrap
4949
(assert-equal ((Y factorial-wrap) three) (mul three two))
5050
(assert-equal ((Y factorial-wrap) four) (mul four (mul three two)))
5151

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-
5852
(define factorial (Y factorial-wrap))
5953

6054
(assert-equal (factorial zero) one)

examples/factorial.lisp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121

2222
;; (assert-equal factorial factorial)
2323

24+
;; (assert-not-same
25+
;; factorial
26+
;; (lambda (x) (factorial x)))
27+
28+
;; (assert-equal
29+
;; factorial
30+
;; (lambda (x) (factorial x)))
31+
2432
;; (assert-equal
2533
;; factorial
2634
;; (lambda (x) (factorial x))

examples/fix.lisp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323

2424
;; The following `Y` is one way of defining `Y`.
2525

26-
(define (Y f)
27-
((lambda (x) (f (x x)))
28-
(lambda (x) (f (x x)))))
26+
(define Y
27+
(lambda (f)
28+
((lambda (u) (u u))
29+
(lambda (x) (f (lambda (t) ((x x) t)))))))
30+
31+
;; (define (Y f)
32+
;; ((lambda (x) (f (x x)))
33+
;; (lambda (x) (f (x x)))))
2934

3035
;; We will have
3136

@@ -38,8 +43,8 @@
3843

3944
;; Another function to find fixpoint is `turing`.
4045

41-
(define (turing-half x y) (y (x x y)))
42-
(define turing (turing-half turing-half))
46+
;; (define (turing-half x y) (y (x x y)))
47+
;; (define turing (turing-half turing-half))
4348

4449
;; We will have
4550

examples/nat-even-odd.lisp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
(import true false if and or not "bool.lisp")
22
(import zero add1 sub1 zero? "nat-church.lisp")
33
(import one two three four "nat-church.lisp")
4-
(import Y "fix.lisp")
54

65
(define (even? n)
76
(if (zero? n) true

0 commit comments

Comments
 (0)