Skip to content

Commit

Permalink
[docs/lang0] simple README.md like inet
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Mar 28, 2024
1 parent 2b9f03f commit 3543554
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# docs

[docs/lang0] simple README.md like inet

[docs/lang1] update NOTE.md
[docs/lang1] fix freshen -- be like lang0 with `usedNames`

Expand Down
8 changes: 8 additions & 0 deletions docs/diary/2024-03-29-interpreter-vs-virtual-machine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Interpreter v.s. Virtual Machine
date: 2024-03-29
---

Note that, when implementing lambda calculus as an interpreter,
the depth of the call stack is limited by the hosting language.
To avoid this limitation we should implement lambda calculus by machine like SECD.
38 changes: 20 additions & 18 deletions docs/lang0/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
# Lang0

# Features
Features:

- Implement call-by-need lazy evaluation.
- A name must be defined before used, thus no mutual recursion.
- Allow recursive in top-level definitions by `(fixpoint)`.

- Allow recursive in top-level definitions.

- No mutual recursion, a name must be defined before used.

- A simple module system with only one API -- `(import)`.
```scheme
;; Statement keywords:
- It can import module from local file or remote URL.
(define name body)
(define (name arg ...) body)
(import "./file.scm")
(assert-equal exp ...)
(assert-not-equal exp ...)
- Two simple testing statements `(assert-equal)` and `(assert-not-equal)`.
- They can handle beta and eta equivalence.
;; Expression keywords:
Note that, when implementing lambda calculus as an interpreter,
the depth of the call stack is limited by the hosting language.
To avoid this limitation we should implement lambda calculus by machine like SECD.
(lambda (name) ret)
(fixpoint name body)
```

# Examples
## Examples

## Boolean
### Boolean

```scheme
(define (true t f) t)
Expand All @@ -38,7 +40,7 @@ To avoid this limitation we should implement lambda calculus by machine like SEC
(not (not (or true false)))
```

## Natural Number by Church encoding
### Natural Number by Church encoding

[ [WIKIPEDIA](https://en.wikipedia.org/wiki/Church_encoding) ]

Expand All @@ -56,7 +58,7 @@ To avoid this limitation we should implement lambda calculus by machine like SEC
(add two two)
```

## Factorial
### Factorial

```scheme
(import "./nat-church.scm"
Expand All @@ -77,7 +79,7 @@ To avoid this limitation we should implement lambda calculus by machine like SEC
(factorial three)
```

## Factorial by fixpoint combinator
### Factorial by fixpoint combinator

[ [WIKIPEDIA](https://en.wikipedia.org/wiki/Fixed-point_combinator) ]

Expand Down Expand Up @@ -117,7 +119,7 @@ To avoid this limitation we should implement lambda calculus by machine like SEC
(factorial four)
```

## Cons the Magnificent
### Cons the Magnificent

```scheme
;; NOTE Temporarily save `car` and `cdr` to a lambda,
Expand Down
18 changes: 7 additions & 11 deletions docs/lang1/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# Lang1

## Statements
```scheme
;; Statement keywords:
```
define -- (define name body)
(define (name arg ...) body)
```
(define name body)
(define (name arg ...) body)
## Expressions
;; Expression keywords:
```
var -- name
ap -- (target arg ...)
fn -- (lambda (name) ret)
let -- (let ((name exp) ...) body)
(lambda (name) ret)
(let ((name exp) ...) body)
```

0 comments on commit 3543554

Please sign in to comment.