Skip to content

Commit 6c8fa4c

Browse files
committed
change dir struct and add some examples
1 parent c1a18d8 commit 6c8fa4c

7 files changed

Lines changed: 65 additions & 619 deletions

File tree

README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
11
# lambda-language
22

3-
## The toy language is written by javascript(undone)
3+
## The toy language is written by javascript(basic now)
4+
5+
### example
6+
7+
```
8+
print_range = λ(a, b) if a <= b {
9+
print(a);
10+
if a + 1 <= b {
11+
print(", ");
12+
print_range(a + 1, b);
13+
}
14+
else
15+
println("");
16+
};
17+
print_range(1, 10);
18+
```
19+
output:
20+
```
21+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
22+
***Result: false
23+
```
24+
25+
```
26+
cons = λ(a, b) λ(f) f(a, b);
27+
car = λ(cell) cell(λ(a, b) a);
28+
cdr = λ(cell) cell(λ(a, b) b);
29+
NIL = λ(f) f(NIL, NIL);
30+
31+
x = cons(1, cons(2, cons(3, cons(4, cons(5, NIL)))));
32+
println(car(x)); # 1
33+
println(car(cdr(x))); # 2
34+
println(car(cdr(cdr(x)))); # 3
35+
println(car(cdr(cdr(cdr(x))))); # 4
36+
println(car(cdr(cdr(cdr(cdr(x)))))); # 5
37+
```
38+
output:
39+
```
40+
1
41+
2
42+
3
43+
4
44+
5
45+
***Result: false
46+
```

0 commit comments

Comments
 (0)