Skip to content

Commit 4725d84

Browse files
committed
test circular imports
1 parent 0146be1 commit 4725d84

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

TODO.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
test circular imports
2-
31
# lazy evaluation
42

53
[problem] we can use `Y`! -- `DelayedApply` can replace `Lazy`? -- what evaluation strategy is this?

examples/nat-even-odd-imported.lisp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(import true false if and or not "bool.lisp")
2+
(import zero add1 sub1 zero? "nat-church.lisp")
3+
(import one two three four "nat-church.lisp")
4+
5+
(import even? "nat-even.lisp")
6+
(import odd? "nat-odd.lisp")
7+
8+
(assert-equal true (even? zero))
9+
(assert-equal true (even? two))
10+
(assert-equal true (even? four))
11+
12+
(assert-equal false (even? one))
13+
(assert-equal false (even? three))
14+
15+
(assert-equal false (odd? zero))
16+
(assert-equal false (odd? two))
17+
(assert-equal false (odd? four))
18+
19+
(assert-equal true (odd? one))
20+
(assert-equal true (odd? three))
21+
22+
;; test equivalence between recursive functions
23+
24+
(assert-equal even? even?)
25+
(assert-equal odd? odd?)
26+
27+
(assert-equal
28+
even?
29+
(lambda (n)
30+
(if (zero? n) true
31+
(odd? (sub1 n)))))
32+
33+
(assert-not-equal
34+
odd?
35+
(lambda (n)
36+
(if (zero? n) true
37+
(odd? (sub1 n)))))

examples/nat-even.lisp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(import true false if and or not "bool.lisp")
2+
(import zero add1 sub1 zero? "nat-church.lisp")
3+
(import one two three four "nat-church.lisp")
4+
(import odd? "nat-odd.lisp")
5+
6+
(define (even? n)
7+
(if (zero? n) true
8+
(odd? (sub1 n))))

examples/nat-odd.lisp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(import true false if and or not "bool.lisp")
2+
(import zero add1 sub1 zero? "nat-church.lisp")
3+
(import one two three four "nat-church.lisp")
4+
(import even? "nat-even.lisp")
5+
6+
(define (odd? n)
7+
(if (zero? n) false
8+
(even? (sub1 n))))

src/lang/evaluate/evaluateWithDelay.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export function evaluateWithDelay(mod: Mod, env: Env, exp: Exp): Value {
1616
value = modFindValue(mod, exp.name)
1717
if (value !== undefined) return value
1818

19-
throw new Error(`Unknown name: ${exp.name}`)
19+
throw new Error(
20+
`[evaluateWithDelay] I meet undefined name: ${exp.name}, in mod: ${mod.url}`,
21+
)
2022
}
2123

2224
case "Lambda": {

0 commit comments

Comments
 (0)