woodrush / sectorlisp-examples

Example programs written for SectorLISP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.
  • 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 (* * *).
  • 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 :
    • 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. Using MACRO, this example implements the backquote macro `, as well as the unquote operation ~.
  • 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 LAMBDAs and MACROs to define a temporary variable. The definitions that occur in LAMBDAs and MACROs do not modify the global variable namespace, and are discarded after evaluating the body of the LAMBDAs and MACROs.
    • 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. LAMBDAs and MACROs 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 :
    • 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.
  • 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
    • A version of eval-macro-define.lisp with a REPL interface. With the combination of print, read, macro, define, progn, and implicit progns inside lambdas and macros, the experience of the REPL should be close to that of modern Lisp dialects.
  • 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:

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.

About

Example programs written for SectorLISP

License:Other


Languages

Language:Common Lisp 87.7%Language:NewLisp 11.1%Language:Python 1.2%