sectorlisp-examples
sectorlisp-examples copied to clipboard
Example programs written for SectorLISP
SectorLISP Examples
This repository contains programs written for 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 for an implementation of a neural network in SectorLISP.
Programs
-
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.
- A BASIC-subset interpreter that runs on the original SectorLISP.
Supports the instructions
-
quine.lisp :
- A quine 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 entry from Rosetta Code.
-
fizzbuzz.lisp :
- Implements Fizzbuzz.
Integers are expressed in unary as the number of atoms in a list, such as
(* * *)
.
- Implements Fizzbuzz.
Integers are expressed in unary as the number of atoms in a list, such as
-
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.
- Implements Fizzbuzz, and shows the results as decimal numbers. For example, 123 is shown as
-
eval-macro.lisp :
- An extended version of the metacircular evaluator in lisp.lisp from the original SectorLISP repository,
supporting a new special form
MACRO
which can be used to construct macros. UsingMACRO
, this example implements the backquote macro`
, as well as the unquote operation~
.
- An extended version of the metacircular evaluator in lisp.lisp from the original SectorLISP repository,
supporting a new special form
-
eval-macro-define.lisp :
- An extended version of eval-macro.lisp, supporting
DEFINE
andPROGN
. -
DEFINE
can be used either at the top level to define a persistent variable, or insideLAMBDA
s andMACRO
s to define a temporary variable. The definitions that occur inLAMBDA
s andMACRO
s do not modify the global variable namespace, and are discarded after evaluating the body of theLAMBDA
s andMACRO
s. -
DEFINE
can be written inside any part of the program, including conditions insideCOND
, parts ofCONS
, 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 andMACRO
s also have an implicitPROGN
, 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 definesDEFMACRO
as a macro. It then usesDEFMACRO
to define a new macroREPQUOTE
, which returns an expression where the input expression is repeated twice.
- An extended version of eval-macro.lisp, supporting
The following programs use the I/O special forms, READ
and PRINT
:
-
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 :
- A BASIC-subset interpreter with a REPL interface.
Supports the commands
LIST
,RUN
,DISCARD
for editing and running BASIC programs.
- A BASIC-subset interpreter with a REPL interface.
Supports the commands
-
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~
usingmacro
.
- A version of eval-macro.lisp with a REPL interface,
supporting the
-
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 implicitprogn
s inside lambdas and macros, the experience of the REPL should be close to that of modern Lisp dialects.
- A version of eval-macro-define.lisp with a REPL interface.
With the combination of
-
mandelbrot.lisp
- Prints the 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 in 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 in the original SectorLISP repository:
- eval-macro.lisp
- eval-macro-define.lisp
- repl-macro.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 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.