https://github.com/sdingcn/clo
a Lisp-like functional language with flexible suspension and resumption
https://github.com/sdingcn/clo
compiler continuation coroutine functional-programming garbage-collection interpreter programming-language quine runtime
Last synced: 4 months ago
JSON representation
a Lisp-like functional language with flexible suspension and resumption
- Host: GitHub
- URL: https://github.com/sdingcn/clo
- Owner: sdingcn
- License: mit
- Created: 2023-05-24T22:21:06.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-29T13:21:01.000Z (4 months ago)
- Last Synced: 2025-06-29T14:27:27.079Z (4 months ago)
- Topics: compiler, continuation, coroutine, functional-programming, garbage-collection, interpreter, programming-language, quine, runtime
- Language: C++
- Homepage:
- Size: 445 KB
- Stars: 15
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# clo

[](https://deepwiki.com/sdingcn/clo)
**Clo** is a small, dynamically-typed, garbage-collected, functional programming language.
Here is its syntax.
```
:= "#" [^\n]* "\n"
:= "." [^\s]+
:=
:= | |
| lambda ( * )
| letrec ( * )
| if
| { + } // sequenced evaluation
| ( * )
| ( * )
| @ // access var in closure's env (can simulate structs)
```
The distinguished feature of clo is serializing
the current program state as a string.
The built-in function `.forkstate` returns
a string encoding the program state,
and when the state is resumed using `.eval` it starts
right after the `.forkstate` call but with a return value of Void type.
This resembles Linux's `fork`, Lisp's `call/cc`, etc.
For example, the following program outputs 0, 1, 2, 2, 3 in order.
Note: `.eval` works on both source code and serialized program state.
```
{
(.putstr "0\n")
(.putstr "1\n")
letrec (state (.forkstate)) {
(.putstr "2\n")
if (.= (.type state) 0) # if it is a void value
(.putstr "3\n")
(.eval state)
}
}
```
See [test/](test/) for more code examples (`*.clo`).
## dependencies
The source code of the interpreter
is standard C++20 and thus can be compiled
by any C++20-conforming compiler.
The current `Makefile` and `CI.py`
need `clang++` (with C++20 support), `make`, and `python3`.
## build and run
```
make -C src/ release
bin/clo
```
`python3 CI.py` (re-)builds the interpreter and runs all tests.