2021-07-21 07:40:40 +00:00
|
|
|
# MOROS Lisp
|
|
|
|
|
|
|
|
A minimalist Lisp interpreter is available in MOROS to extend the capabilities
|
|
|
|
of the Shell.
|
|
|
|
|
2022-06-06 14:02:34 +00:00
|
|
|
MOROS Lisp is a Lisp-1 dialect inspired by Scheme and Clojure.
|
|
|
|
|
2021-08-12 21:15:28 +00:00
|
|
|
It started from [Risp](https://github.com/stopachka/risp) and was extended to
|
2021-07-21 07:40:40 +00:00
|
|
|
include the seven primitive operators and the two special forms of John
|
|
|
|
McCarthy's paper "Recursive Functions of Symbolic Expressions and Their
|
|
|
|
Computation by Machine" (1960) and "The Roots of Lisp" (2002) by Paul Graham.
|
|
|
|
|
2021-12-12 10:43:57 +00:00
|
|
|
In version 0.2.0 the whole implementation was refactored and the parser was
|
|
|
|
rewritten to use [Nom](https://github.com/Geal/nom). This allowed the addition
|
|
|
|
of strings to the language and reading from the filesystem.
|
|
|
|
|
2021-07-21 07:40:40 +00:00
|
|
|
## Seven Primitive Operators
|
|
|
|
- `quote` (with the `'` syntax)
|
|
|
|
- `atom` (aliased to `atom?`)
|
|
|
|
- `eq` (aliased to `eq?`)
|
|
|
|
- `car` (aliased to `first`)
|
|
|
|
- `cdr` (aliased to `rest`)
|
|
|
|
- `cons`
|
|
|
|
- `cond`
|
|
|
|
|
|
|
|
## Two Special Forms
|
|
|
|
- `label` (aliased to `def`)
|
|
|
|
- `lambda` (aliased to `fn`)
|
|
|
|
|
2021-12-12 10:43:57 +00:00
|
|
|
## Additional Builtins
|
2021-07-21 07:40:40 +00:00
|
|
|
- `defun` (aliased to `defn`)
|
2021-12-12 10:43:57 +00:00
|
|
|
- `mapcar` (aliased to `map`)
|
2021-07-21 07:40:40 +00:00
|
|
|
- `print`
|
2021-12-12 10:43:57 +00:00
|
|
|
- `read-file`
|
|
|
|
- `lines`
|
|
|
|
- `parse`
|
2021-07-21 07:40:40 +00:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
The interpreter can be invoked from the shell:
|
|
|
|
|
|
|
|
```
|
|
|
|
> lisp
|
|
|
|
MOROS Lisp v0.1.0
|
|
|
|
|
|
|
|
> (+ 1 2)
|
|
|
|
3
|
|
|
|
|
2022-06-26 08:00:54 +00:00
|
|
|
> (quit)
|
2021-07-21 07:40:40 +00:00
|
|
|
```
|
|
|
|
|
2021-12-12 10:43:57 +00:00
|
|
|
And it can execute a file. For example a file located in `/tmp/fibonacci.lsp`
|
|
|
|
with the following content:
|
2021-07-21 07:40:40 +00:00
|
|
|
|
|
|
|
```lisp
|
2022-06-06 14:02:34 +00:00
|
|
|
(defn fib (n)
|
|
|
|
(cond
|
|
|
|
((< n 2) n)
|
|
|
|
(true (+ (fib (- n 1)) (fib (- n 2))))))
|
2021-07-21 07:40:40 +00:00
|
|
|
|
2022-06-06 14:02:34 +00:00
|
|
|
(println (fib 10))
|
2021-07-21 07:40:40 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Would produce the following output:
|
|
|
|
|
|
|
|
```
|
2021-12-12 10:43:57 +00:00
|
|
|
> lisp /tmp/fibonacci.lsp
|
2022-06-06 14:02:34 +00:00
|
|
|
55
|
2021-07-21 07:40:40 +00:00
|
|
|
```
|