https://github.com/woodrush/sectorlisp-examples
Example programs written for SectorLISP
https://github.com/woodrush/sectorlisp-examples
lisp sectorlisp
Last synced: about 1 month ago
JSON representation
Example programs written for SectorLISP
- Host: GitHub
- URL: https://github.com/woodrush/sectorlisp-examples
- Owner: woodrush
- License: other
- Created: 2022-01-07T13:07:39.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-03T03:21:45.000Z (almost 3 years ago)
- Last Synced: 2025-01-27T12:24:07.761Z (3 months ago)
- Topics: lisp, sectorlisp
- Language: Common Lisp
- Homepage:
- Size: 49.8 KB
- Stars: 22
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SectorLISP Examples
This repository contains programs written for [SectorLISP](https://github.com/jart/sectorlisp),
a 512-byte Lisp interpreter that fits inside the boot sector of a floppy disk and runs on bare metal.Please also see [sectorlisp-nn](https://github.com/woodrush/sectorlisp-nn) for an implementation of a neural network in SectorLISP.
## Programs
- [basic.lisp](./lisp/basic.lisp) :
- A BASIC-subset interpreter that runs on the original SectorLISP.
Supports the instructions `REM`, `LET`, `IF`, `GOTO`, `PRINT`, and the infix operators `+`, `-`, `%`, and `<=`.
Integers are expressed in unary as the number of atoms in a list, such as `(1 1 1)`.
A slightly modified version where the program is brought to the end is shown in [basic-2.lisp](./lisp/basic-2.lisp).
- [quine.lisp](./lisp/quine.lisp) :
- A [quine](https://en.wikipedia.org/wiki/Quine_(computing)) for SectorLISP,
which is a program that prints its own source code when evaluated, without the use of any external input.
When evaluated in the SectorLISP REPL, the output exactly matches the input itself.
The technique used in this code is referenced from the Common Lisp quine in the [Quine](https://rosettacode.org/wiki/Quine#Common_Lisp) entry from [Rosetta Code](https://rosettacode.org/wiki/Rosetta_Code).
- [fizzbuzz.lisp](./lisp/fizzbuzz.lisp) :
- Implements [Fizzbuzz](https://en.wikipedia.org/wiki/Fizz_buzz).
Integers are expressed in unary as the number of atoms in a list, such as `(* * *)`.
- [fizzbuzz-decimal.lisp](./lisp/fizzbuzz-decimal.lisp) :
- Implements Fizzbuzz, and shows the results as decimal numbers. For example, 123 is shown as `(1 2 3)`.
Since the computation is rather heavy, it takes a little bit of time for the results to be shown.
- [eval-macro.lisp](./lisp/eval-macro.lisp) :
- An extended version of the metacircular evaluator in [lisp.lisp](https://github.com/jart/sectorlisp/blob/main/lisp.lisp) from the [original SectorLISP repository](https://github.com/jart/sectorlisp),
supporting a new special form `MACRO` which can be used to construct macros.
Using `MACRO`, this example implements the backquote macro `` ` ``, as well as the unquote operation `~`.
- [eval-macro-define.lisp](./lisp/eval-macro-define.lisp) :
- An extended version of eval-macro.lisp, supporting `DEFINE` and `PROGN`.
- `DEFINE` can be used either at the top level to define a persistent variable,
or inside `LAMBDA`s and `MACRO`s to define a temporary variable.
The definitions that occur in `LAMBDA`s and `MACRO`s do not modify the global variable namespace,
and are discarded after evaluating the body of the `LAMBDA`s and `MACRO`s.
- `DEFINE` can be written inside any part of the program, including conditions inside `COND`, parts of `CONS`, etc.,
and will successfully modify the surrounding variable namespace.
- Due to the introduction of side effects, there is also support for `PROGN`,
with the same behavior as modern Lisp dialects.
`LAMBDA`s and `MACRO`s also have an implicit `PROGN`, and multiple statements can be written inside its body
which will be evaluated sequentially in the order of appearance, as in modern Lisp dialects.
- This example first defines the backquote macro `` ` `` and the unquote operation `~`,
and then defines `DEFMACRO` as a macro.
It then uses `DEFMACRO` to define a new macro `REPQUOTE`, which returns an expression where the input expression is repeated twice.The following programs use the I/O special forms, `READ` and `PRINT`:
- [number-guessing-game.lisp](./lisp/number-guessing-game.lisp) :
- An interactive number guessing game where the player guesses a
secret number from 1 to 10, using incremental knowledge of whether the guess was less than or greater than the secret number.
- [basic-repl.lisp](./lisp/basic-repl.lisp) :
- A BASIC-subset interpreter with a REPL interface.
Supports the commands `LIST`, `RUN`, `DISCARD` for editing and running BASIC programs.
- [repl-macro.lisp](./lisp/repl-macro.lisp) :
- A version of eval-macro.lisp with a REPL interface,
supporting the `macro` special form which can be used to construct macros.
This example also implements the backquote macro `` ` ``, as well as the unquote operation `~` using `macro`.
- [repl-macro-define.lisp](./lisp/repl-macro-define.lisp)
- A version of eval-macro-define.lisp with a REPL interface.
With the combination of `print`, `read`, `macro`, `define`, `progn`, and implicit `progn`s inside lambdas and macros,
the experience of the REPL should be close to that of modern Lisp dialects.
- [mandelbrot.lisp](./lisp/mandelbrot.lisp)
- Prints the [Mandelbrot Set](https://en.wikipedia.org/wiki/Mandelbrot_set) at a 37x79 resolution.
- Since SectorLISP does not have a built-in feature for integers or fractions,
fixed point numbers are implemented from scratch only using symbolic expressions.
- The library used for the fixed point number system is available as [numsectorlisp](https://github.com/woodrush/numsectorlisp/blob/main/numsectorlisp.lisp)
in [numsectorlisp](https://github.com/woodrush/numsectorlisp).
- This program takes an incredibly long amount of time to finish running on Blinkenlights,
which took about one day to finish running.
You can also run this program on QEMU using the test scripts under `./test` in the SectorLISP repository.
- The output of the program is as follows:
```
........................................................*......................
...............................................................................
...............................................................................
...........................................................*...................
........................................................*..**..................
.........................................................*******...*...........
.......................................................*********.....*.........
..................................................**...*********...............
.............................................*****.****************.......*....
................................*.............***************************......
...........................................*****************************.......
.........................*.................******************************......
.............................*.....*......********************************.....
..........................**.**..**.*..*..*********************************....
............................************.**********************************....
......................*...***.********************************************.....
......................**..************************************************.....
..................**....*************************************************......
......*****************************************************************........
..................**....*************************************************......
......................**..************************************************.....
......................*...***.********************************************.....
............................************.**********************************....
..........................**.**..**.*..*..*********************************....
.............................*.....*......********************************.....
.........................*.................******************************......
...........................................*****************************.......
................................*.............***************************......
.............................................*****.****************.......*....
..................................................**...*********...............
.......................................................*********.....*.........
.........................................................*******...*...........
........................................................*..**..................
...........................................................*...................
...............................................................................
...............................................................................
........................................................*......................
```## Licensing
The following programs are based on [lisp.lisp](https://github.com/jart/sectorlisp/blob/main/lisp.lisp) in the [original SectorLISP repository](https://github.com/jart/sectorlisp):
- [eval-macro.lisp](./lisp/eval-macro.lisp)
- [eval-macro-define.lisp](./lisp/eval-macro-define.lisp)
- [repl-macro.lisp](./lisp/repl.lisp)
- [repl-macro-define.lisp](./lisp/repl-macro-define.lisp)These codes are associated with the ISC license from the original SectorLISP repository as well as the MIT license for this repository.
The [LICENSE](LICENSE) file in this repository includes the ISC license from the original SectorLISP repository as well.Other programs were written solely by Hikaru Ikuta, and are associated with only the MIT License in [LICENSE](LICENSE).