diff --git a/CHANGELOG.md b/CHANGELOG.md
index 38c963d..c487ddf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,16 +1,6 @@
# Change Log
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
-## [0.3.0] - 2023-04-10
-
-### Changed
-
-- Added property lists in the exact format used by Lisp 1.5;
-- Added `ASSOC`, `EFFACE`, `MAPLIST`, `PROG`, and other functions;
-- Where there are both interpreted (`EXPR`) and Clojure (`SUBR`) implementations of the same function, the `EXPR` is preferred (it is planned to make this configurable if/when there is a working compiler);
-- More error messages/diagnostics are now printed in Old English (it is planned to implement internationalisation so that you can switch to messages you actually understand);
-- Documentation improvements.
-
## [0.2.1] - 2023-03-30
### Changed
diff --git a/README.md b/README.md
index 430ce62..cf8a848 100644
--- a/README.md
+++ b/README.md
@@ -1,80 +1,30 @@
# beowulf
-## Þý liste cræfte spræc
-
LISP 1.5 is to all Lisp dialects as Beowulf is to English literature.
-
-
-## Contents
- * [What this is](#what-this-is)
- + [Status](#status)
- + [BUT WHY?!!?!](#but-why-----)
- + [Project Target](#project-target)
- + [Invoking](#invoking)
- + [Building and Invoking](#building-and-invoking)
- + [Reader macros](#reader-macros)
- + [Functions and symbols implemented](#functions-and-symbols-implemented)
- + [Architectural plan](#architectural-plan)
- - [resources/lisp1.5.lsp](#resources-lisp15lsp)
- - [beowulf/boostrap.clj](#beowulf-boostrapclj)
- - [beowulf/host.clj](#beowulf-hostclj)
- - [beowulf/read.clj](#beowulf-readclj)
- + [Commentary](#commentary)
- * [Installation](#installation)
- + [Input/output](#input-output)
- - [SYSOUT](#sysout)
- - [SYSIN](#sysin)
- * [Learning Lisp 1.5](#learning-lisp-15)
- * [Other Lisp 1.5 resources](#other-lisp-15-resources)
- + [Other implmentations](#other-implementations)
- + [History resources](#history-resources)
- * [License](#license)
-
-Table of contents generated with markdown-toc
-
## What this is
A work-in-progress towards an implementation of Lisp 1.5 in Clojure. The
objective is to build a complete and accurate implementation of Lisp 1.5
as described in the manual, with, in so far as is possible, exactly the
-same behaviour — except as documented below.
-
-### BUT WHY?!!?!
-
-Because.
-
-Because Lisp is the only computer language worth learning, and if a thing
-is worth learning, it's worth learning properly; which means going back to
-the beginning and trying to understand that.
-
-Because there is, so far as I know, no working implementation of Lisp 1.5
-for modern machines.
-
-Because I'm barking mad, and this is therapy.
+same bahaviour - except as documented below.
### Status
-Working Lisp interpreter, but some key features not yet implemented.
+Boots to REPL, but few functions yet available.
* [Project website](https://simon-brooke.github.io/beowulf/).
* [Source code documentation](https://simon-brooke.github.io/beowulf/docs/codox/index.html).
-### Project Target
+### Building and Invoking
-The project target is to be able to run the [Wang algorithm for the propositional calculus](https://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf#page=52) given in chapter 8 of the *Lisp 1.5 Programmer's Manual*. When that runs, the project is as far as I am concerned feature complete. I may keep tinkering with it after that and I'll certainly accept pull requests which are in the spirit of the project (i.e. making Beowulf more usable, and/or implementing parts of Lisp 1.5 which I have not implemented), but this isn't intended to be a new language for doing real work; it's an educational and archaeological project, not serious engineering.
+Build with
-Some `readline`-like functionality would be really useful, but my attempt to integrate [JLine](https://github.com/jline/jline3) has not (yet) been successful.
-
-An in-core structure editor would be an extremely nice thing, and I may well implement one.
-
-You are of course welcome to fork the project and do whatever you like with it!
-
-### Invoking
+ lein uberjar
Invoke with
- java -jar target/uberjar/beowulf-0.3.0-standalone.jar --help
+ java -jar target/uberjar/beowulf-0.2.1-SNAPSHOT-standalone.jar --help
(Obviously, check your version number)
@@ -83,128 +33,107 @@ Command line arguments as follows:
```
-h, --help Print this message
-p PROMPT, --prompt PROMPT Set the REPL prompt to PROMPT
- -r INITFILE, --read SYSOUTFILE Read Lisp sysout from the file SYSOUTFILE
- (defaults to `resources/lisp1.5.lsp`)
- -s, --strict Strictly interpret the Lisp 1.5 language,
- without extensions.
+ -r INITFILE, --read INITFILE Read Lisp functions from the file INITFILE
+ -s, --strict Strictly interpret the Lisp 1.5 language, without extensions.
```
To end a session, type `STOP` at the command prompt.
-### Building and Invoking
-
-Build with
-
- lein uberjar
-
-
### Reader macros
-Currently `SETQ` and `DEFUN` are implemented as reader macros, sort of. It would
-now be possible to reimplement them as `FEXPRs` and so the reader macro functionality will probably go away.
+Currently I don't have
### Functions and symbols implemented
+The following functions and symbols are implemented:
+
| Function | Type | Signature | Implementation | Documentation |
|--------------|----------------|------------------|----------------|----------------------|
-| NIL | Lisp variable | ? | | The canonical empty list. See manual pages 22, 69s |
-| T | Lisp variable | ? | | The canonical true value. See manual pages 22, 69 |
-| F | Lisp variable | ? | | The canonical false value. See manual pages 22, 69 |
-| ADD1 | Host lambda function | x:number | | Add one to the number `x`. |
-| AND | Host lambda function | expr* | PREDICATE | `T` if and only if none of my `args` evaluate to either `F` or `NIL`, else `F`.
In `beowulf.host` principally because I don't yet feel confident to define varargs functions in Lisp. |
-| APPEND | Lisp lambda function | ? | | see manual pages 11, 61 |
-| APPLY | Host lambda function | ? | | Apply this `function` to these `arguments` in this `environment` and return the result.
For bootstrapping, at least, a version of APPLY written in Clojure.
All args are assumed to be symbols or `beowulf.cons-cell/ConsCell` objects.
See page 13 of the Lisp 1.5 Programmers Manual. |
-| ASSOC | Lisp lambda function, Host lambda function | a:list | ? | If a is an association list such as the one formed by PAIRLIS in the above example, then assoc will produce the first pair whose first term is x. Thus it is a table searching function. All args are assumed to be `beowulf.cons-cell/ConsCell` objects. See page 12 of the Lisp 1.5 Programmers Manual.
**NOTE THAT** this function is overridden by an implementation in Lisp, but is currently still present for bootstrapping. |
-| ATOM | Host lambda function | x:expr | PREDICATE | Returns `T` if and only if the argument `x` is bound to an atom; else `F`. It is not clear to me from the documentation whether `(ATOM 7)` should return `T` or `F`. I'm going to assume `T`. |
-| CAR | Host lambda function | list | | Return the item indicated by the first pointer of a pair. NIL is treated specially: the CAR of NIL is NIL. |
-| CAAAAR | Lisp lambda function | list | ? | ? |
-| CAAADR | Lisp lambda function | list | ? | ? |
-| CAAAR | Lisp lambda function | list | ? | ? |
-| CAADAR | Lisp lambda function | list | ? | ? |
-| CAADDR | Lisp lambda function | list | ? | ? |
-| CAADR | Lisp lambda function | list | ? | ? |
-| CAAR | Lisp lambda function | list | ? | ? |
-| CADAAR | Lisp lambda function | list | ? | ? |
-| CADADR | Lisp lambda function | list | ? | ? |
-| CADAR | Lisp lambda function | list | ? | ? |
-| CADDAR | Lisp lambda function | list | ? | ? |
-| CADDDR | Lisp lambda function | list | ? | ? |
-| CADDR | Lisp lambda function | list | ? | ? |
-| CADR | Lisp lambda function | list | ? | ? |
-| CDAAAR | Lisp lambda function | list | ? | ? |
-| CDAADR | Lisp lambda function | list | ? | ? |
-| CDAAR | Lisp lambda function | list | ? | ? |
-| CDADAR | Lisp lambda function | list | ? | ? |
-| CDADDR | Lisp lambda function | list | ? | ? |
-| CDADR | Lisp lambda function | list | ? | ? |
-| CDAR | Lisp lambda function | list | ? | ? |
-| CDDAAR | Lisp lambda function | list | ? | ? |
-| CDDADR | Lisp lambda function | list | ? | ? |
-| CDDAR | Lisp lambda function | list | ? | ? |
-| CDDDAR | Lisp lambda function | list | ? | ? |
-| CDDDDR | Lisp lambda function | list | ? | ? |
-| CDDDR | Lisp lambda function | list | ? | ? |
-| CDDR | Lisp lambda function | list | ? | ? |
-| CDR | Host lambda function | list | | Return the item indicated by the second pointer of a pair. NIL is treated specially: the CDR of NIL is NIL. |
-| CONS | Host lambda function | expr, expr | | Construct a new instance of cons cell with this `car` and `cdr`. |
-| CONSP | Host lambda function | o:expr | ? | Return `T` if object `o` is a cons cell, else `F`.
**NOTE THAT** this is an extension function, not available in strict mode. I believe that Lisp 1.5 did not have any mechanism for testing whether an argument was, or was not, a cons cell. |
-| COPY | Lisp lambda function | ? | | see manual pages 62 |
-| DEFINE | Host lambda function | ? | PSEUDO-FUNCTION | Bootstrap-only version of `DEFINE` which, post boostrap, can be overwritten in LISP. The single argument to `DEFINE` should be an association list of symbols to lambda functions. See page 58 of the manual. |
-| DIFFERENCE | Host lambda function | x:number, y:number | | Returns the result of subtracting the number `y` from the number `x` |
-| DIVIDE | Lisp lambda function | x:number, y:number | | see manual pages 26, 64 |
-| DOC | Host lambda function | ? | ? | Open the page for this `symbol` in the Lisp 1.5 manual, if known, in the default web browser.
**NOTE THAT** this is an extension function, not available in strct mode. |
-| EFFACE | Lisp lambda function | ? | PSEUDO-FUNCTION | see manual pages 63 |
-| ERROR | Host lambda function | ? | PSEUDO-FUNCTION | Throw an error |
-| EQ | Host lambda function | ? | PREDICATE | Returns `T` if and only if both `x` and `y` are bound to the same atom, else `NIL`. |
-| EQUAL | Host lambda function | ? | PREDICATE | This is a predicate that is true if its two arguments are identical S-expressions, and false if they are different. (The elementary predicate `EQ` is defined only for atomic arguments.) The definition of `EQUAL` is an example of a conditional expression inside a conditional expression. NOTE: returns `F` on failure, not `NIL` |
-| EVAL | Host lambda function | ? | | Evaluate this `expr` and return the result. If `environment` is not passed, it defaults to the current value of the global object list. The `depth` argument is part of the tracing system and should not be set by user code. All args are assumed to be numbers, symbols or `beowulf.cons-cell/ConsCell` objects. However, if called with just a single arg, `expr`, I'll assume it's being called from the Clojure REPL and will coerce the `expr` to `ConsCell`. |
-| FACTORIAL | Lisp lambda function | ? | ? | ? |
-| FIXP | Host lambda function | ? | PREDICATE | ? |
-| GENSYM | Host lambda function | ? | | Generate a unique symbol. |
-| GET | Host lambda function | ? | | From the manual: '`get` is somewhat like `prop`; however its value is car of the rest of the list if the `indicator` is found, and NIL otherwise.'
It's clear that `GET` is expected to be defined in terms of `PROP`, but we can't implement `PROP` here because we lack `EVAL`; and we can't have `EVAL` here because both it and `APPLY` depends on `GET`.
OK, It's worse than that: the statement of the definition of `GET` (and of) `PROP` on page 59 says that the first argument to each must be a list; But the in the definition of `ASSOC` on page 70, when `GET` is called its first argument is always an atom. Since it's `ASSOC` and `EVAL` which I need to make work, I'm going to assume that page 59 is wrong. |
-| GREATERP | Host lambda function | ? | PREDICATE | ? |
-| INTEROP | Host lambda function | ? | ? | ? |
-| INTERSECTION | Lisp lambda function | ? | ? | ? |
-| LENGTH | Lisp lambda function | ? | | see manual pages 62 |
-| LESSP | Host lambda function | ? | PREDICATE | ? |
-| MAPLIST | Lisp lambda function | ? | FUNCTIONAL | see manual pages 20, 21, 63 |
-| MEMBER | Lisp lambda function | ? | PREDICATE | see manual pages 11, 62 |
-| MINUSP | Lisp lambda function | ? | PREDICATE | see manual pages 26, 64 |
-| NOT | Lisp lambda function | ? | PREDICATE | see manual pages 21, 23, 58 |
-| NULL | Lisp lambda function | ? | PREDICATE | see manual pages 11, 57 |
-| NUMBERP | Host lambda function | ? | PREDICATE | ? |
-| OBLIST | Host lambda function | ? | | Return a list of the symbols currently bound on the object list.
**NOTE THAT** in the Lisp 1.5 manual, footnote at the bottom of page 69, it implies that an argument can be passed but I'm not sure of the semantics of this. |
-| ONEP | Lisp lambda function | ? | PREDICATE | see manual pages 26, 64 |
-| OR | Host lambda function | ? | PREDICATE | `T` if and only if at least one of my `args` evaluates to something other than either `F` or `NIL`, else `F`.
In `beowulf.host` principally because I don't yet feel confident to define varargs functions in Lisp. |
-| PAIR | Lisp lambda function | ? | | see manual pages 60 |
-| PAIRLIS | Lisp lambda function, Host lambda function | ? | ? | This function gives the list of pairs of corresponding elements of the lists `x` and `y`, and APPENDs this to the list `a`. The resultant list of pairs, which is like a table with two columns, is called an association list. Essentially, it builds the environment on the stack, implementing shallow binding.
All args are assumed to be `beowulf.cons-cell/ConsCell` objects. See page 12 of the Lisp 1.5 Programmers Manual.
**NOTE THAT** this function is overridden by an implementation in Lisp, but is currently still present for bootstrapping. |
-| PLUS | Host lambda function | ? | | ? |
-| PRETTY | | ? | ? | ? |
-| PRINT | | ? | PSEUDO-FUNCTION | see manual pages 65, 84 |
-| PROG | Host nlambda function | ? | | The accursed `PROG` feature. See page 71 of the manual.
Lisp 1.5 introduced `PROG`, and most Lisps have been stuck with it ever since. It introduces imperative programming into what should be a pure functional language, and consequently it's going to be a pig to implement. Broadly, `PROG` is a variadic pseudo function called as a `FEXPR` (or possibly an `FSUBR`, although I'm not presently sure that would even work.) The arguments, which are unevaluated, are a list of forms, the first of which is expected to be a list of symbols which will be treated as names of variables within the program, and the rest of which (the 'program body') are either lists or symbols. Lists are treated as Lisp expressions which may be evaulated in turn. Symbols are treated as targets for the `GO` statement.
- **GO:** A `GO` statement takes the form of `(GO target)`, where `target` should be one of the symbols which occur at top level among that particular invocation of `PROG`s arguments. A `GO` statement may occur at top level in a PROG, or in a clause of a `COND` statement in a `PROG`, but not in a function called from the `PROG` statement. When a `GO` statement is evaluated, execution should transfer immediately to the expression which is the argument list immediately following the symbol which is its target. If the target is not found, an error with the code `A6` should be thrown.
- **RETURN:** A `RETURN` statement takes the form `(RETURN value)`, where `value` is any value. Following the evaluation of a `RETURN` statement, the `PROG` should immediately exit without executing any further expressions, returning the value.
- **SET and SETQ:** In addition to the above, if a `SET` or `SETQ` expression is encountered in any expression within the `PROG` body, it should affect not the global object list but instead only the local variables of the program.
- **COND:** In **strict** mode, when in normal execution, a `COND` statement none of whose clauses match should not return `NIL` but should throw an error with the code `A3`... *except* that inside a `PROG` body, it should not do so. *sigh*.
**Flow of control:** Apart from the exceptions specified above, expressions in the program body are evaluated sequentially. If execution reaches the end of the program body, `NIL` is returned.
Got all that? Good. |
-| PROP | Lisp lambda function | ? | FUNCTIONAL | see manual pages 59 |
-| QUOTE | Lisp lambda function | ? | | see manual pages 10, 22, 71 |
-| QUOTIENT | Host lambda function | ? | | I'm not certain from the documentation whether Lisp 1.5 `QUOTIENT` returned the integer part of the quotient, or a realnum representing the whole quotient. I am for now implementing the latter. |
-| RANGE | Lisp lambda function | ? | ? | ? |
-| READ | Host lambda function | ? | PSEUDO-FUNCTION | An implementation of a Lisp reader sufficient for bootstrapping; not necessarily the final Lisp reader. `input` should be either a string representation of a LISP expression, or else an input stream. A single form will be read. |
-| REMAINDER | Host lambda function | ? | | ? |
-| REPEAT | Lisp lambda function | ? | ? | ? |
-| RPLACA | Host lambda function | ? | PSEUDO-FUNCTION | Replace the `CAR` pointer of this `cell` with this `value`. Dangerous, should really not exist, but does in Lisp 1.5 (and was important for some performance hacks in early Lisps) |
-| RPLACD | Host lambda function | ? | PSEUDO-FUNCTION | Replace the `CDR` pointer of this `cell` with this `value`. Dangerous, should really not exist, but does in Lisp 1.5 (and was important for some performance hacks in early Lisps) |
-| SEARCH | Lisp lambda function | ? | FUNCTIONAL | see manual pages 63 |
-| SET | Host lambda function | ? | PSEUDO-FUNCTION | Implementation of SET in Clojure. Add to the `oblist` a binding of the value of `var` to the value of `val`.
**NOTE WELL**: this is not SETQ! |
-| SUB1 | Lisp lambda function, Host lambda function | ? | | ? |
-| SUB2 | Lisp lambda function | ? | ? | ? |
-| SUBLIS | Lisp lambda function | ? | | see manual pages 12, 61 |
-| SUBST | Lisp lambda function | ? | | see manual pages 11, 61 |
-| SYSIN | Host lambda function | ? | ? | Read the contents of the file at this `filename` into the object list. If the file is not a valid Beowulf sysout file, this will probably corrupt the system, you have been warned. File paths will be considered relative to the filepath set when starting Lisp. It is intended that sysout files can be read both from resources within the jar file, and from the file system. If a named file exists in both the file system and the resources, the file system will be preferred.
**NOTE THAT** if the provided `filename` does not end with `.lsp` (which, if you're writing it from the Lisp REPL, it won't), the extension `.lsp` will be appended.
**NOTE THAT** this is an extension function, not available in strct mode. |
-| SYSOUT | Host lambda function | ? | ? | Dump the current content of the object list to file. If no `filepath` is specified, a file name will be constructed of the symbol `Sysout` and the current date. File paths will be considered relative to the filepath set when starting Lisp.
**NOTE THAT** this is an extension function, not available in strict mode. |
-| TERPRI | | ? | PSEUDO-FUNCTION | see manual pages 65, 84 |
-| TIMES | Host lambda function | ? | | ? |
-| TRACE | Host lambda function | ? | PSEUDO-FUNCTION | Add this `s` to the set of symbols currently being traced. If `s` is not a symbol or sequence of symbols, does nothing. |
-| UNION | Lisp lambda function | ? | ? | ? |
-| UNTRACE | Host lambda function | ? | PSEUDO-FUNCTION | Remove this `s` from the set of symbols currently being traced. If `s` is not a symbol or sequence of symbols, does nothing. |
-| ZEROP | Lisp lambda function | ? | PREDICATE | see manual pages 26, 64 |
+| NIL | Lisp variable | | | ? |
+| T | Lisp variable | | | ? |
+| F | Lisp variable | | | ? |
+| ADD1 | Host function | (ADD1 X) | | ? |
+| AND | Host function | (AND & ARGS) | PREDICATE | `T` if and only if none of my `args` evaluate to either `F` or `NIL`, else `F`. In `beowulf.host` principally because I don't yet feel confident to define varargs functions in Lisp. |
+| APPEND | Lisp function | (APPEND X Y) | LAMBDA-fn | see manual pages 11, 61 |
+| APPLY | Host function | (APPLY FUNCTION ARGS ENVIRONMENT DEPTH) | | Apply this `function` to these `arguments` in this `environment` and return the result. For bootstrapping, at least, a version of APPLY written in Clojure. All args are assumed to be symbols or `beowulf.cons-cell/ConsCell` objects. See page 13 of the Lisp 1.5 Programmers Manual. |
+| ATOM | Host function | (ATOM X) | PREDICATE | Returns `T` if and only if the argument `x` is bound to an atom; else `F`. It is not clear to me from the documentation whether `(ATOM 7)` should return `T` or `F`. I'm going to assume `T`. |
+| CAR | Host function | (CAR X) | | Return the item indicated by the first pointer of a pair. NIL is treated specially: the CAR of NIL is NIL. |
+| CAAAAR | Lisp function | (CAAAAR X) | LAMBDA-fn | ? |
+| CAAADR | Lisp function | (CAAADR X) | LAMBDA-fn | ? |
+| CAAAR | Lisp function | (CAAAR X) | LAMBDA-fn | ? |
+| CAADAR | Lisp function | (CAADAR X) | LAMBDA-fn | ? |
+| CAADDR | Lisp function | (CAADDR X) | LAMBDA-fn | ? |
+| CAADR | Lisp function | (CAADR X) | LAMBDA-fn | ? |
+| CAAR | Lisp function | (CAAR X) | LAMBDA-fn | ? |
+| CADAAR | Lisp function | (CADAAR X) | LAMBDA-fn | ? |
+| CADADR | Lisp function | (CADADR X) | LAMBDA-fn | ? |
+| CADAR | Lisp function | (CADAR X) | LAMBDA-fn | ? |
+| CADDAR | Lisp function | (CADDAR X) | LAMBDA-fn | ? |
+| CADDDR | Lisp function | (CADDDR X) | LAMBDA-fn | ? |
+| CADDR | Lisp function | (CADDR X) | LAMBDA-fn | ? |
+| CADR | Lisp function | (CADR X) | LAMBDA-fn | ? |
+| CDAAAR | Lisp function | (CDAAAR X) | LAMBDA-fn | ? |
+| CDAADR | Lisp function | (CDAADR X) | LAMBDA-fn | ? |
+| CDAAR | Lisp function | (CDAAR X) | LAMBDA-fn | ? |
+| CDADAR | Lisp function | (CDADAR X) | LAMBDA-fn | ? |
+| CDADDR | Lisp function | (CDADDR X) | LAMBDA-fn | ? |
+| CDADR | Lisp function | (CDADR X) | LAMBDA-fn | ? |
+| CDAR | Lisp function | (CDAR X) | LAMBDA-fn | ? |
+| CDDAAR | Lisp function | (CDDAAR X) | LAMBDA-fn | ? |
+| CDDADR | Lisp function | (CDDADR X) | LAMBDA-fn | ? |
+| CDDAR | Lisp function | (CDDAR X) | LAMBDA-fn | ? |
+| CDDDAR | Lisp function | (CDDDAR X) | LAMBDA-fn | ? |
+| CDDDDR | Lisp function | (CDDDDR X) | LAMBDA-fn | ? |
+| CDDDR | Lisp function | (CDDDR X) | LAMBDA-fn | ? |
+| CDDR | Lisp function | (CDDR X) | LAMBDA-fn | ? |
+| CDR | Host function | (CDR X) | | Return the item indicated by the second pointer of a pair. NIL is treated specially: the CDR of NIL is NIL. |
+| CONS | Host function | (CONS CAR CDR) | | Construct a new instance of cons cell with this `car` and `cdr`. |
+| COPY | Lisp function | (COPY X) | LAMBDA-fn | see manual pages 62 |
+| DEFINE | Host function | (DEFINE ARGS) | PSEUDO-FUNCTION | Bootstrap-only version of `DEFINE` which, post boostrap, can be overwritten in LISP. The single argument to `DEFINE` should be an assoc list which should be nconc'ed onto the front of the oblist. Broadly, (SETQ OBLIST (NCONC ARG1 OBLIST)) |
+| DIFFERENCE | Host function | (DIFFERENCE X Y) | | ? |
+| DIVIDE | Lisp function | (DIVIDE X Y) | LAMBDA-fn | see manual pages 26, 64 |
+| ERROR | Host function | (ERROR & ARGS) | PSEUDO-FUNCTION | Throw an error |
+| EQ | Host function | (EQ X Y) | PREDICATE | Returns `T` if and only if both `x` and `y` are bound to the same atom, else `NIL`. |
+| EQUAL | Host function | (EQUAL X Y) | PREDICATE | This is a predicate that is true if its two arguments are identical S-expressions, and false if they are different. (The elementary predicate `EQ` is defined only for atomic arguments.) The definition of `EQUAL` is an example of a conditional expression inside a conditional expression. NOTE: returns `F` on failure, not `NIL` |
+| EVAL | Host function | (EVAL EXPR); (EVAL EXPR ENV DEPTH) | | Evaluate this `expr` and return the result. If `environment` is not passed, it defaults to the current value of the global object list. The `depth` argument is part of the tracing system and should not be set by user code. All args are assumed to be numbers, symbols or `beowulf.cons-cell/ConsCell` objects. |
+| FACTORIAL | Lisp function | (FACTORIAL N) | LAMBDA-fn | ? |
+| FIXP | Host function | (FIXP X) | PREDICATE | ? |
+| GENSYM | Host function | (GENSYM ) | | Generate a unique symbol. |
+| GET | Lisp function | (GET X Y) | LAMBDA-fn | see manual pages 41, 59 |
+| GREATERP | Host function | (GREATERP X Y) | PREDICATE | ? |
+| INTEROP | Host function | (INTEROP FN-SYMBOL ARGS) | (INTEROP) | Clojure (or other host environment) interoperation API. `fn-symbol` is expected to be either 1. a symbol bound in the host environment to a function; or 2. a sequence (list) of symbols forming a qualified path name bound to a function. Lower case characters cannot normally be represented in Lisp 1.5, so both the upper case and lower case variants of `fn-symbol` will be tried. If the function you're looking for has a mixed case name, that is not currently accessible. `args` is expected to be a Lisp 1.5 list of arguments to be passed to that function. Return value must be something acceptable to Lisp 1.5, so either a symbol, a number, or a Lisp 1.5 list. If `fn-symbol` is not found (even when cast to lower case), or is not a function, or the value returned cannot be represented in Lisp 1.5, an exception is thrown with `:cause` bound to `:interop` and `:detail` set to a value representing the actual problem. |
+| INTERSECTION | Lisp function | (INTERSECTION X Y) | LAMBDA-fn | ? |
+| LENGTH | Lisp function | (LENGTH L) | LAMBDA-fn | see manual pages 62 |
+| LESSP | Host function | (LESSP X Y) | PREDICATE | ? |
+| MEMBER | Lisp function | (MEMBER A X) | LAMBDA-fn | see manual pages 11, 62 |
+| MINUSP | Lisp function | (MINUSP X) | LAMBDA-fn | see manual pages 26, 64 |
+| NOT | Lisp function | (NOT X) | LAMBDA-fn | see manual pages 21, 23, 58 |
+| NULL | Lisp function | (NULL X) | LAMBDA-fn | see manual pages 11, 57 |
+| NUMBERP | Host function | (NUMBERP X) | PREDICATE | ? |
+| OBLIST | Host function | (OBLIST ) | | Return a list of the symbols currently bound on the object list. **NOTE THAT** in the Lisp 1.5 manual, footnote at the bottom of page 69, it implies that an argument can be passed but I'm not sure of the semantics of this. |
+| ONEP | Lisp function | (ONEP X) | LAMBDA-fn | see manual pages 26, 64 |
+| PAIR | Lisp function | (PAIR X Y) | LAMBDA-fn | see manual pages 60 |
+| PLUS | Host function | (PLUS & ARGS) | | ? |
+| PRETTY | Lisp variable | | (PRETTY) | ? |
+| PRINT | Lisp variable | | PSEUDO-FUNCTION | ? |
+| PROP | Lisp function | (PROP X Y U) | LAMBDA-fn | see manual pages 59 |
+| QUOTIENT | Host function | (QUOTIENT X Y) | | I'm not certain from the documentation whether Lisp 1.5 `QUOTIENT` returned the integer part of the quotient, or a realnum representing the whole quotient. I am for now implementing the latter. |
+| RANGE | Lisp variable | ? | (RANGE (LAMBDA (N M) (COND ((LESSP M N) (QUOTE NIL)) ((QUOTE T) (CONS N (RANGE (ADD1 N) M)))))) | ? |
+| READ | Host function | (READ ); (READ INPUT) | PSEUDO-FUNCTION | An implementation of a Lisp reader sufficient for bootstrapping; not necessarily the final Lisp reader. `input` should be either a string representation of a LISP expression, or else an input stream. A single form will be read. |
+| REMAINDER | Host function | (REMAINDER X Y) | | ? |
+| REPEAT | Lisp function | (REPEAT N X) | LAMBDA-fn | ? |
+| RPLACA | Host function | (RPLACA CELL VALUE) | PSEUDO-FUNCTION | Replace the CAR pointer of this `cell` with this `value`. Dangerous, should really not exist, but does in Lisp 1.5 (and was important for some performance hacks in early Lisps) |
+| RPLACD | Host function | (RPLACD CELL VALUE) | PSEUDO-FUNCTION | Replace the CDR pointer of this `cell` with this `value`. Dangerous, should really not exist, but does in Lisp 1.5 (and was important for some performance hacks in early Lisps) |
+| SET | Host function | (SET SYMBOL VAL) | PSEUDO-FUNCTION | Implementation of SET in Clojure. Add to the `oblist` a binding of the value of `var` to the value of `val`. NOTE WELL: this is not SETQ! |
+| SUB1 | Lisp function | (SUB1 N) | LAMBDA-fn | see manual pages 26, 64 |
+| SYSIN | Host function | (SYSIN ); (SYSIN FILENAME) | (SYSIN) | Read the contents of the file at this `filename` into the object list. If the file is not a valid Beowulf sysout file, this will probably corrupt the system, you have been warned. File paths will be considered relative to the filepath set when starting Lisp. It is intended that sysout files can be read both from resources within the jar file, and from the file system. If a named file exists in both the file system and the resources, the file system will be preferred. **NOTE THAT** if the provided `filename` does not end with `.lsp` (which, if you're writing it from the Lisp REPL, it won't), the extension `.lsp` will be appended. |
+| SYSOUT | Host function | (SYSOUT ); (SYSOUT FILEPATH) | (SYSOUT) | Dump the current content of the object list to file. If no `filepath` is specified, a file name will be constructed of the symbol `Sysout` and the current date. File paths will be considered relative to the filepath set when starting Lisp. |
+| TERPRI | Lisp variable | | PSEUDO-FUNCTION | ? |
+| TIMES | Host function | (TIMES & ARGS) | | ? |
+| TRACE | Host function | (TRACE S) | PSEUDO-FUNCTION | Add this symbol `s` to the set of symbols currently being traced. If `s` is not a symbol, does nothing. |
+| UNTRACE | Host function | (UNTRACE S) | PSEUDO-FUNCTION | ? |
+| ZEROP | Lisp function | (ZEROP N) | LAMBDA-fn | see manual pages 26, 64 |
+
Functions described as 'Lisp function' above are defined in the default
sysout file, `resources/lisp1.5.lsp`, which will be loaded by default unless
@@ -216,7 +145,8 @@ over the Clojure implementations.
### Architectural plan
-Not everything documented in this section is yet built. It indicates the direction of travel and intended destination, not the current state.
+Not everything documented in this section is yet built. It indicates the
+direction of travel and intended destination, not the current state.
#### resources/lisp1.5.lsp
@@ -265,6 +195,19 @@ Intended deviations from the behaviour of the real Lisp reader are as follows:
a comment, as most modern Lisps do; but I do not believe Lisp 1.5 had
this feature.
+### BUT WHY?!!?!
+
+Because.
+
+Because Lisp is the only computer language worth learning, and if a thing
+is worth learning, it's worth learning properly; which means going back to
+the beginning and trying to understand that.
+
+Because there is, so far as I know, no working implementation of Lisp 1.5
+for modern machines.
+
+Because I'm barking mad, and this is therapy.
+
### Commentary
What's surprised me in working on this is how much more polished Lisp 1.5 is
@@ -282,19 +225,11 @@ but this is software which is almost sixty years old).
## Installation
-Download the latest [release 'uberjar'](https://github.com/simon-brooke/beowulf/releases) and run it using:
+At present, clone the source and build it using
-```bash
- java -jar
-```
+`lein uberjar`.
-Or clone the source and build it using:
-
-```bash
- lein uberjar`
-```
-
-To build it you will require to have [Leiningen](https://leiningen.org/) installed.
+You will require to have [Leiningen](https://leiningen.org/) installed.
### Input/output
@@ -327,14 +262,7 @@ processors, but I failed to find the Lisp source of Lisp functions as a text
file, which is why `resources/lisp1.5.lsp` is largely copytyped and
reconstructed from the manual.
-### Other implementations
-
-There's an online (browser native) Lisp 1.5 implementation [here](https://pages.zick.run/ichigo/) (source code [here](https://github.com/zick/IchigoLisp)). It
-even has a working compiler!
-
-### History resources
-
-I'm compiling a [list of links to historical documents on Lisp 1.5](https://simon-brooke.github.io/beowulf/docs/further_reading.html).
+I'm not at this time aware of any other working Lisp 1.5 implementations.
## License
diff --git a/doc/further_reading.md b/doc/further_reading.md
index 3dfd32c..9d97f5a 100644
--- a/doc/further_reading.md
+++ b/doc/further_reading.md
@@ -1,16 +1,7 @@
# Further Reading
1. [CODING for the MIT-IBM 704 COMPUTER, October 1957](http://bitsavers.org/pdf/mit/computer_center/Coding_for_the_MIT-IBM_704_Computer_Oct57.pdf)
- This paper is not about Lisp. But it is about the particular individual computer on which Lisp was first implemented, and it is written in part by members of the Lisp team. I have found it useful in understanding the software environment in which, and the constraints under which, Lisp was written.
2. [MIT AI Memo 1, John McCarthy, September 1958](https://www.softwarepreservation.org/projects/LISP/MIT/AIM-001.pdf)
- This is, as far as I can find, the earliest specification document of the Lisp project.
3. [Lisp 1 Programmer's Manual, Phyllis Fox, March 1960](https://bitsavers.org/pdf/mit/rle_lisp/LISP_I_Programmers_Manual_Mar60.pdf)
4. [Lisp 1.5 Programmer's Manual, Michael I. Levin, August 1962](https://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf#page=81)
- This book is essential reading: it documents in some detail the first fully realised Lisp language system.
5. [Early LISP History (1956 - 1959), Herbert Stoyan, August 1984](https://dl.acm.org/doi/pdf/10.1145/800055.802047#page=3)
-
-
-6. [The Roots of Lisp, Paul Graham, 2001](http://www.paulgraham.com/rootsoflisp.html)
-6. [The Revenge of the Nerds, Paul Graham, 2002](http://www.paulgraham.com/icad.html)
- This is mainly about why to use Lisp as a language for modern commercial software, but has useful insights into where it comes from.
- > So the short explanation of why this 1950s language is not obsolete is that it was not technology but math, and math doesn't get stale.
\ No newline at end of file
diff --git a/doc/lisp1.5.md b/doc/lisp1.5.md
index 6042cc8..f4b0946 100644
--- a/doc/lisp1.5.md
+++ b/doc/lisp1.5.md
@@ -5,10 +5,10 @@
**Massachusetts Institute of Technology**
-> [John McCarthy](https://en.wikipedia.org/wiki/John_McCarthy_(computer_scientist))
-> [Paul W. Abrahams](https://mitpress.mit.edu/author/paul-w-abrahams-31449/)
-> [Daniel J. Edwards](https://www.chessprogramming.org/Daniel_Edwards)
-> [Timothy P. Hart](https://www.chessprogramming.org/Timothy_Hart)
+> John McCarthy
+> Paul W. Abrahams
+> Daniel J. Edwards
+> Timothy P. Hart
> The M. I.T. Press
> Massachusetts Institute of Technology
@@ -43,11 +43,11 @@ The over-all design of the LISP Programming System is the work of John McCarthy
This manual was written by Michael I. Levin.
-The interpreter was programmed by [Stephen B. Russell](https://en.wikipedia.org/wiki/Steve_Russell_(computer_scientist)) and Daniel J. Edwards. The print and read programs were written by John McCarthy, Klim Maling, Daniel J. Edwards, and Paul W. Abrahams.
+The interpreter was programmed by Stephen B. Russell and Daniel J. Edwards. The print and read programs were written by John McCarthy, Klim Maling, Daniel J. Edwards, and Paul W, Abrahams.
The garbage collector and arithmetic features Were written by Daniel J. Edwards. The compiler and assembler were written by Timothy P. Hart and Michael I. Levin. An earlier compiler was written by Robert Brayton.
-The "LISP 1 Programmer's Manual" March 1, 1960, was written by [Phyllis A. Fox](https://en.wikipedia.org/wiki/Phyllis_Fox). Additional programs and suggestions were contributed by the following members of the Artificial Intelligence Group of the Research Laboratory of Electronics: Marvin L. Minsky, Bertram Raphael, Louis Hodes, David M. R. Park, David C. Luckham, Daniel G. Bobrow, James R. Slagle, and Nathaniel Rochester.
+The "LISP 1 Programmer's Manual" March 1, 1960, was written by Phyllis A. Fox. Additional programs and suggestions were contributed by the following members of the Artificial Intelligence Group of the Research Laboratory of Electronics: Marvin L. Minsky, Bertram Raphael, Louis Hodes, David M. R. Park, David C. Luckham, Daniel G. Bobrow, James R. Slagle, and Nathaniel Rochester.
August 17, 1962
@@ -387,7 +387,7 @@ The Euclidean algorithm for finding the greatest common divisor of two positive
```
gcd[x; y]=[x>y -> gcd[y; x];
- rem[y;x]=0 -> x]
+ rem[y;x]=0 -> x]
```
`rem[u; v]` is the remainder when `u` is divided by `v`.
@@ -575,9 +575,9 @@ This function gives the result of substituting the S-expression x for all occurr
```
subst[x; y; z] = [equal[y; z] -> x;
- atom[z] - z;
- T - cons[subst
- [x; y; car[z]]; subst[x; y; cdr[z]]]]
+ atom[z] - z;
+ T - cons[subst
+ [x; y; car[z]]; subst[x; y; cdr[z]]]]
```
As an example, we have
@@ -607,8 +607,8 @@ append[(A B);(C D E)] = (A B C D E)
This predicate is true if the S-expression `x` occurs among the elements of the list `y`. We have
```
member[x; y] = [null[y] -> F;
- equal[x; car [y ]] ->T;
- T -> member[x; cdr [y ]]]
+ equal[x; car [y ]] ->T;
+ T -> member[x; cdr [y ]]]
```
#### 3. pairlis[x; y; a]
@@ -621,8 +621,8 @@ two columns, is called an association list. We have
```
pairlis [x; y; a] = [null[x] -> a;
- T -> cons[cons[car[x]; car[y]];
- pairlis[cdr[x]; cdr [y]; a]]]
+ T -> cons[cons[car[x]; car[y]];
+ pairlis[cdr[x]; cdr [y]; a]]]
```
An example is
@@ -658,13 +658,13 @@ from the pair list. In order to define `sublis`, we first define an auxiliary fu
```
sub2[a; z] = [null[a] -> z; eq[caar[a]; z] -> cdar[a];
- T -> sub2[cdr[a]; z]]
+ T -> sub2[cdr[a]; z]]
```
and
```
sublis[a; y] = [atom[y] -> sub2[a; y];
- T -> cons[sublis[a; car[y]]; sublis[a; cdr[y]]]]
+ T -> cons[sublis[a; car[y]]; sublis[a; cdr[y]]]]
```
An example is
@@ -707,35 +707,35 @@ evalquote[fn; x] = apply[fn; x; NIL]
where
```mexpr
apply[fn; x; a] =
- [atom[fn] -> [eq[fn; CAR] -> caar[x]
- eq[fn; CDR] -> cdar[x];
- eq[fn; CONS] -> cons[car[x]; cadr[x]];
- eq[fn; ATOM] -> atom[car[x]];
- eq[fn; EQ] -> eq[car[x]; cadr[x]];
- T -> apply[eval[fn; a]; x; a]]
- eq[car[fn]; LAMBDA] -> eval[caddr[fn]; pairlis[cadr[fn]; x; a]];
- eq[car[fn]; LABEL] -> apply[caddr [fn]; x; cons[cons[cadr [fn];
- caddr[fn]]; a]]]
+ [atom[fn] -> [eq[fn; CAR] -> caar[x]
+ eq[fn; CDR] -> cdar[x];
+ eq[fn; CONS] -> cons[car[x]; cadr[x]];
+ eq[fn; ATOM] -> atom[car[x]];
+ eq[fn; EQ] -> eq[car[x]; cadr[x]];
+ T -> apply[eval[fn; a]; x; a]]
+ eq[car[fn]; LAMBDA] -> eval[caddr[fn]; pairlis[cadr[fn]; x; a]];
+ eq[car[fn]; LABEL] -> apply[caddr [fn]; x; cons[cons[cadr [fn];
+ caddr[fn]]; a]]]
eval[e;a] = [atom[e] -> cdr[assoc[e;a]];
- atom[car[e]] -> [eq[car[e]; QUOTE] -> cadr[e];
- eq[car[e]; COND] -> evcon[cdr[e]; a];
- T -> apply[car[e]; evlis[cdr[el; a]; a]];
- T -> apply[car[e]; evlis [cdr[e]; a]; a]]
+ atom[car[e]] -> [eq[car[e]; QUOTE] -> cadr[e];
+ eq[car[e]; COND] -> evcon[cdr[e]; a];
+ T -> apply[car[e]; evlis[cdr[el; a]; a]];
+ T -> apply[car[e]; evlis [cdr[e]; a]; a]]
```
`pairlis` and `assoc` have been previously defined.
```mexpr
evcon[c; a] = [eval[caar[c]; a] -> eval[cadar[c]; a];
- T -> evcon[cdr [c];a]]
+ T -> evcon[cdr [c];a]]
```
and
```mexpr
evlis[m; a] = [null[m] -> NIL;
- T -> cons [eval[car [m];a];evlis[cdr [m];a]]]
+ T -> cons [eval[car [m];a];evlis[cdr [m];a]]]
```
page 14
@@ -780,11 +780,11 @@ The following example is a LISP program that defines three functions `union`, `i
```
member[a; x] = [null[x] -> F; eq[a; car[x]] -> T;
- T -> member[a; cdr[x]]]
+ T -> member[a; cdr[x]]]
union[x; y] = [null[x] -> y;
- member[car[x];y] -> union[cdr[x]; y];
- T -> cons[car[x]; union[cdr[x]; y]]]
+ member[car[x];y] -> union[cdr[x]; y];
+ T -> cons[car[x]; union[cdr[x]; y]]]
intersection[x;y] = [null[x] -> NIL;
member[car[x]; y] -> cons[car[x]; intersection[cdr[x]; y]];
@@ -2719,8 +2719,8 @@ erty list for FF.
The function `prop` searches the list `x` for an item that is `eq` to `y`. If such an element is found, the value of `prop` is the rest of the list beginning immediately after the element. Otherwise the value is `u[]`, where u is a function of no arguments.
```
prop[x; y; u] = [null[x] -> u[ ];
- eq[car[x];y] -> cdr[x]
- T -> prop[cdr[x]; y; u]]
+ eq[car[x];y] -> cdr[x]
+ T -> prop[cdr[x]; y; u]]
```
SUBR
```
@@ -2816,14 +2816,13 @@ Note that the following M-expression is different from that given in Section I,
the result is the same.
```
-sublis[x;y] = [null[x] -> y;
- null[y] -> y;
- T -> search[x;
- lambda[[j]; equal[y;caar[j]]];
- lambda[[j]; cdar[j]];
- lambda[[j]; [atom[y] -> y;
- T -> cons[sublis[x; car[y]];
- sublis[x; cdr[y]]]]]]]
+sublis[x;y] [null[x] -- y;
+null[y] -- y;
+T -. search[x;
+k[[j]; equal[y;caar[j]]];
+k[[j]; cdar[j]];
+k[[j];[atom[y] - y;
+T -c cons [sublis [x;car [y]];sublis [x;cdr [y]]]]]]]
```
### List Handling Functions
@@ -3292,136 +3291,127 @@ NIL
by performing
EVAL (OBLIST NIL).
-page 70
-
## APPENDIX B : THE LISP INTERPRETER
-This appendix is written in mixed M-expressions and English. Its purpose is to describe as closely as possible the actual working of the interpreter and PROG feature. The functions `evalquote`, `apply`, `eval`, `evlis`, `evcon`, and the `PROG` feature are defined by using a language that follows the M-expression notation as closely as possible and contains some insertions in English.
+This appendix is written in mixed M-expressions and English. Its purpose is to
+describe as closely as possible the actual working of the interpreter and PROG feature.
+The functions evalquote, ---- apply, eval, evlis, evcon, and the PROG feature are defined
+by using a language that follows the M-expression notation as closely as possible and
+contains some insertions in English.
-```mexpr
-evalquote[fn; args]=[get[fn; FEXPR] v get[fn; FSUBR] -> eval[cons [ fn; args]; NIL];
- T -> apply[fn; args; NIL]
-```
+###### evalquote[fn;args]=[get [fn; FEXPR] vget [fn; FSUBR] -
-This definition shows that `evalquote` is capable of handling special forms as a sort of exception. Apply cannot handle special forms and will give error `A2` if given one as its first argument.
-
-The following definition of `apply` is an enlargement of the one given in Section I. It shows how functional arguments bound by FUNARG are processed, and describes the way in which machine language subroutines are called.
-
-In this description, `spread` can be regarded as a pseudo-function of one argument. This argument is a list. `spread` puts the individual items of this list into the AC, MQ,
-$ARG3,... the standard cells *[general purpose registers]* for transmitting arguments to functions.
+eval[cons [ fn; args]; NIL]
+This definition shows that evalquote is capable of handling special forms as a sort
+of exception. Apply cannot handle special forms and will give error A2 if given one as
+its first argument.
+The following definition'of apply is an enlargement of the one given in Section I. It
+shows how functional arguments bound by FUNARG are processed, and describes the
+way in which machine language subroutines are called.
+In this description, spread can be regarded as a pseudo-function of one argument.
+This argument is a list. spread puts the individual items of this list into the AC, MQ,
+$ARG3,... the standard cells for transmitting arguments to functions.
These M-expressions should not be taken too literally. In many cases, the actual
program is a store and transfer where a recursion is suggested by these definitions.
+apply[fn;args;a]=[
+null [fn]-NIL;
+at ~rn[fn]-[~et [fn; EXPR]-~~~~~ [expr^1 ; args ; a];
+spread[args];
-```mexpr
-apply[fn; args; a]=[
- null[fn] -> NIL;
- atom[fn] -> [get[fn; EXPR] -> apply[expr ; args ; a];
- get[fn; subr] -> {spread[args];
- $ALIST := a;
- TSX subr, 4};
- T -> apply[cdr[sassoc[fn; a; lambda[[];error [A2]]]]; args ;a];
- eq[car[fn]; LABEL] -> apply[caddr[fn];args;
- cons[cons[cadr[fn];
- caddr[fn]];a]];
- eq[car[fn]; FUNARG] -> apply[cadr[fn]; args; caddr[fn]];
- eq[car [fn]; LAMBDA] -> eval[caddr[fn];
- nconc [pair[cadr[fn]; args]; a]];
- T -> apply[eval[fn; a]; args; a]]
-```
-*NOTE THAT the formatting of this MEXPR is beyond the capabilities of Markdown to reproduce; this is a rational reconstruction, but to be perfectly certain of the interpretation consult the PDF*
+T-apply[cdr[sassoc [fn;a;~[[];error [~2]]]];ar~s ;a];
+eq[car[fn]; ~~~~~]-a~~l~[caddr[fn];ar~s;cons[cons[cadr[fn];caddr[fn]];a]];
+eq[car[fn]; ~~~~~~]-a~~1~[cadr [fn]; args; caddr [fn]];
+eq[car [fn]; LAMBDA]-eval[caddr[fn]; nconc [pair[cadr[fn]; args]; a]];
+~-a~~ly[eval[fn;a];ar~s ;a]]
+1. The value of get is set aside. This is the meaning of the apparent free or unde-
+ fined variable -
+* eval[f orm; a]= [
+ null[f orm]-NIL;
+ numberp[f orm]-f orm;
+ atom[form]-[get[f O~~;APVAL]-car [apval^1 1;
+ ~~cdr[sassoc[form;a;~[[ ];error[A8]]]]];
+ eq[car[f O~~];QUOTE]-cadr [form]; 2
+ eq[car [form]; FUNCTION]-~~~~[FUNARG; cadr [form];a];
+ eq[car [form]; COND]-evcon[cdr[form]; a];
+ eq[car [form]; ~~OG]-~ro~[cdr [form]; a];
+ atom[car[form]] -[get[car [form];~~~~]-~a~~l~[ex~r;^1 evlis[cdr lforrn];a];a];
+ get[car[form];~~~~~]-apply[fexpr !list[cdr [form];a];a];
+ spread[evlis [cdr [form]; a]];
+ get[car[form];~~~~]-
+ TSX subr f 4
+ AC: =cdr [ form];
+ get[car[form];F~u~R]-, MQ: = $ALIST: =a; ;
------
-
-1. The value of get is set aside. This is the meaning of the apparent free or undefined variable.
-
-page 71
-
-```mexpr
-eval[form; a]= [
- null[form] -> NIL;
- numberp[form] -> form;
- atom[form] -> [get[form; APVAL] -> car[apval];
- T -> cdr[sassoc[form; a; lambda[[ ]; error[A8]]]]];
- eq[car[form]; QUOTE] -> cadr[form];
- eq[car[form]; FUNCTION] -> list[FUNARG; cadr[form]; a];
- eq[car [form]; COND] -> evcon[cdr[form]; a];
- eq[car [form]; PROG] -> prog[cdr[form]; a];
- atom[car[form]] -> [get[car [form]; EXPR] ->
- apply[expr; evlis[cdr[form]; a]; a];
- get[car[form]; FEXPR] ->
- apply[fexpr; list[cdr[form]; a]; a];
- get[car[form]; SUBR] -> {spread[evlis[cdr[form]; a]];
- $ALIST := a;
- TSX subr 4};
- get[car[form]; FSUBR] -> {AC := cdr[form];
- MQ := $ALIST := a;
- TSX fsubr 4}
- T -> eval[cons[cdr[sassoc[car[form]; a;
- lambda[[];error[A9]]]];
- cdr[form]]; a]];
- T-apply [car [form];evlis [cdr [form]; a]; a]]
-
-evcon[c; a] = [null[c] -> error[A3];
- eval[caar[c]; a] -> eval[cadar[a]; a];
- T -> evcon[cdr[ c]; a]]
-
-evlis[m; a] = maplist[m; lambda[[j]; eval[car[j]; a]]]
-```
-### The PROG Feature
+# (TSx fsubr!4 }
+~-e~al[~0ns[cdr[sas~0~[car[form];a;~[[];error[~9]]]];
+cdr [form]]; a]];
+T-apply [car [form];evlis [cdr [form]; a]; a]]
+evcon[c; a]= [null[c]--error [A3];
+eval[caar[ c]; a]-eval[cadar [a];a];
+T-evcon[cdr [ c];a]]
+evlis[ - m; a] =maplist [m; ~[[j]; eval[car[j]; a]]]
+The PROG Feature
The PROG feature is an FSUBR coded into the system. It can best be explained in
English, although it is possible to define it by using M-expressions.
1. As soon as the PROG feature is entered, the list of program variables is used
-to make a new list in which each one is paired with NIL. This is then appended to the current a-list. Thus each program variable is set to NIL at the entrance to the program.
+to make a new list in which each one is paired with NIL. This is then appended to the
+current a-list. Thus each program variable is set to NIL at the entrance to the program.
2. The remainder of the program is searched for atomic symbols that are under-
-stood to be location symbols. A go-list is formed in which each location symbol is paired with a pointer into the remainder of the program.
-3. When a set or a setq - is encountered, the name of the variable is located on the a-list. The value of the variable (or cdr of the pair) is actually replaced with the new value.
+stood to be location symbols. A go-list is formed in which each location symbol is
+paired with a pointer into the remainder of the program.
+3. When a set or a setq - is encountered, the name of the variable is located on the
+a-list. The value of the variable (or cs of the pair) is actually replaced with the new
+value.
+1. The value of get is set aside. This is the meaning of the apparent free or unde-
+fined variable-
+2. In the actual system this is handled by an FSUBR rather than as the separate special
+case as shown here.
------
-1. The value of get is set aside. This is the meaning of the apparent free or undefined variable.
-2. In the actual system this is handled by an FSUBR rather than as the separate special case as shown here.
+If the variable is bound several times on the a-list, only the first or most recent
+occurrence is changed. If the current binding of the variable is at a higher level than
+the entrance to the prog, then the change will remain in effect throughout the scope
+of that binding, and the old value will be lost.
+If the variable does not occur on the a-list, then error diagnostic A4 or A5 will
+occur.
-page 72
-
-If the variable is bound several times on the a-list, only the first or most recent occurrence is changed. If the current binding of the variable is at a higher level than the entrance to the prog, then the change will remain in effect throughout the scope of that binding, and the old value will be lost.
-
-If the variable does not occur on the a-list, then error diagnostic `A4` or `A5` will occur.
-
-4. When a return is encountered at any point, its argument is evaluated and returned as the value of the most recent prog that has been entered.
+4. When a return is encountered at any point, its argument is evaluated and returned
+as the value of the most recent prog that has been entered.
5. The form go may be used only in two ways.
- a. `(GO X)` may occur on the top level of the prog, `x` must be a location symbol of this `prog` and not another one on a higher or lower level.
- b. This form may also occur as one of the value parts of a conditional expression, if this conditional expression occurs on the top level of the `prog`.
- If a `go` is used incorrectly or refers to a nonexistent location, error diagnostic `A6` will occur.
-
-6. When the form cond occurs on the top level of a `prog`, it differs from other
- `cond`s in the following ways.
- a. It is the only instance in which a `go` can occur inside a `cond`.
- b. If the `cond` runs out of clauses, error diagnostic `A3` will not occur. Instead, the `prog` will continue with the next statement.
-
+a. (GO X) may occur on the top level of the prog, x must be a location symbol
+of this prog and not another one on a higher or lower level.
+b. This form may also occur as one of the value parts of a conditional expres-
+sion, if this conditional expression occurs on the top level of the prog.
+If a go - is used incorrectly or refers to a nonexistent location, error diagnostic A6
+will occur.
+6. When the form cond occurs on the top level of a prog, it differs from other
+conds in the following ways.
+a. It is the only instance in which a gocan occur inside a cond.
+b. If the cond runs out of clauses, error diagnostic A3 will not occur. Instead,
+the prog will c6ntinue with the next statement.
7. When a statement is executed, this has the following meaning, with the exception
- of the special forms `cond`, `go`, `return`, `setq` and the pseudo-function `set`, all of which are peculiar to `prog`.
- The statement `s` is executed by performing `eval[s;a]`, where `a` is the current a-list, and then ignoring the value.
-
+of the special forms cond, go, return, setq and the pseudo-functionset, all of which
+are peculiar to prog.
+The statement 5 is executed by performing eval[s;a], where 2 is the current a-list,
+and then ignoring the value.
8. If a prog runs out of statements, its value is NIL.
- When a prog - is compiled, it will have the same effect as when it is interpreted, although the method of execution is much different; for example, a go is always cornpiled as a transfer. The following points should be noted concerning declared variables.1
- 1. Program variables follow the same rules as h variables do.
- a. If a variable is purely local, it need not be declared.
- b. Special variables can be used as free variables in compiled functions. They may be set at a lower level than that at which they are bound.
- c. Common program variables maintain complete communication between compiled programs and the interpreter.
-
- 2. & as distinct from setq can only be used to set common variables.
-
-
------
+When a prog - is compiled, it will have the same effect as when it is interpreted,
+although the method of execution is much different; for example, a go is always corn-
+piled as a transfer. The following points should be noted concerning declared variables.^1
+1. Program variables follow the same rules as h variables do.
+a. If a variable is purely local, it need not be declared.
+b. Special variables can be used as free variables in compiled functions. They
+may be set at a lower level than that at which they are bound.
+c. Common program variables maintain complete communication between com-
+piled programs and the interpreter.
+2. & as distinct from setq can only be used to set common variables.
1. See Appendix D for an explanation of variable declaration.
-page 73
-
-## APPENDIX C : THE LISP ASSEMBLY PROGRAM (LAP)
+APPENDIX C : THE LISP ASSEMBLY PROGRAM (LAP)
lap is a two-pass assembler. It was specifically designed for use by the new com-
piler, but it can also be used for defining functions in machine language, and for making
@@ -3465,9 +3455,6 @@ FSUBR. n is the number of arguments which the subroutine expects.
Symbols
Atomic symbols appearing on the listing (except NIL or the first item on the listing)
-
-page 74
-
are treated as location symbols. The appearance of the symbol defines it as the location
of the next instruction in the listing. During pass one, these symbols and their values
are made into a pair list, and appended to the initial symbol table to form the final sym-
@@ -3513,8 +3500,6 @@ literal will not be created if it is equal to one that already exists.
4. If the field is of the form (SPECIAL x), then the value is the address of the
SPECIAL cell on the property list of x. If one does not already exist, it will be created.
-page 75
-
The SPECIAL cell itself (but not the entire atom) is protected against garbage collection.
5. In all other cases, the field is assumed to be a list of subfields, and their sum
@@ -3581,10 +3566,8 @@ LAP ( (6217Q (TRA NIL) )NIL)
LAP ( (NIL (CLA A) (TSX 6204Q) (TRA B) )
( (A 6243Q) (B 6220Q) ) )
-page 76
-
-## APPENDIX D : THE LISP COMPILER
-
+APPENDIX D
+THE LISP COMPILER
The LISP Compiler is a program written in LISP that translates S-expression defi-
nitions of functions into machine language subroutines. It is an optional feature that
makes programs run many times faster than they would if they were to be interpreted
@@ -3597,13 +3580,12 @@ space. Thus an EXPR, or an FEXPR, has been changed to a SUBR or an FSUBR,
respectively.
Experience has shown that compiled programs run anywhere from 10 to 100 times
as fast as interpreted programs, the time depending upon the nature of the program.
-Compiled programs are also more economical with memory than their corresponding
-S-expressions, taking only from 50 per cent to 80 per cent as much space.1
+Compiled programs are also more economical with memory than their corresponding 1
+S-expressions, taking only from 50 per cent to 80 per cent as much space.'
The major part of the compiler is a translator or function from the S-expression
function notation into the assembly language, LAP. The only reasons why the compiler
is regarded as a pseudo-function are that it calls LAP, and it removes EXPRts and
FEXPR1s when it has finished compiling.
-
The compiler has an interesting and perhaps unique history. It was developed in
the following steps:
@@ -3618,20 +3600,18 @@ tape is created, the entire compiler was punched out in assembly language by usi
punc hlap.
4. When a system tape is to be made, the compiler in assembly language is read
in by using readlap.
+The compiler is called by using the pseudo-function compile. The argument of com-
-The compiler is called by using the pseudo-function compile. The argument of compile is a list of the names of functions to be compiled. Each atomic symbol on this list
+- pile is a list of the names of functions to be compiled. Each atomic symbol on this list
should have either an EXPR or an FEXPR on its property list before being compiled.
The processing of each function occurs in three steps. First, the S-expression for
the function is translated into assembly language. If no S-expression is found, then the
compiler will print this fact and proceed with the next function. Second, the assembly
------
1. Since the compiled program is binary program space, which is normally
not otherwise accessible, one gains as free storage the total space formerly occupied
by the S-expression definition.
-page 77
-
language program is assembled by LAP. Finally, if no error has occurred, then the
EXPR or FEXPR is removed from the property list. When certain errors caused by
undeclared free variables occur, the compiler will print a diagnostic and continue.
@@ -3678,8 +3658,6 @@ When a variable is used free, it must have been bound by a higher level function
If a program is being run interpretively, and a free variable is used without having been
bound on a higher level, error diagnostic *A^89 will occur.
-page 78
-
If the program is being run compiled, the diagnostic may not occur, and the variable
may have value NIL.
There are three types of variables in compiled functions: ordinary variables,
@@ -3721,8 +3699,6 @@ Consider the following definition of a function dot by using an S-expression:
(YDOT (LAMBDA (X Y) (MAPLIST X (FUNCTION
(LAMBDA (J) (CONS (CAR J) Y)) ))))
-page 79
-
Following the word FUNCTION is a functional constant. If we consider it as a sep-
arate function, it is evident that it contains a bound variable "Jtt, and a free variable
"Yfl. This free variable must be declared SPECIAL or COMMON, even though it is
@@ -3757,8 +3733,6 @@ form the instruction TSX and plant this on top of the STR.
2. Once a direct TSX link is made, this particular calling point will not be traced.
(Link will not make a TSX as long as the called function is being traced. )
-page 80
-
## APPENDIX E : OVERLORD - THE MONITOR
Overlord is the monitor of the LISP System. It controls the handling of tapes, the
@@ -3799,8 +3773,6 @@ card columns to use are as follows.
address data word
-page 81
-
Overlord cards have the Overlord direction beginning in column 8. If the card has
no other field, then comments may begin in column 16. Otherwise, the other fields of
the card begin in column 16 and are separated by commas. The comments may begin
@@ -3861,8 +3833,6 @@ Causes the computer to halt. An end of file mark is written on SYSPOT. An end
of file is written on SYSPPT only if it has been used. If the FIN card was read on-line,
the computer halts after doing these things. If the FIN card came from SYSPIT, then
-page 82
-
SYSPIT is advanced past the next end of file mark before the halt occurs.
Use of Sense Switches
@@ -3886,8 +3856,6 @@ become a system tape containing the basic system plus any changes that have been
onto it. It may be mounted on the SYSTAP drive for some future run to use definitions
that have been set onto it.
-page 83
-
## APPENDIX F : LISP INPUT AND OUTPUT
This appendix describes the LISP read and write programs and the character-
@@ -3929,8 +3897,6 @@ b. The first two characters must not be $ $.
c. It must be delimited on either side by a character from class C.
There is a provision for reading in atomic symbols containing arbitrary characters.
-page 84
-
This is done by punching the form $$dsd, where s is any string of up to 30 characters,
and d is any character not contained in the string s. Only the string s is used in
forming the print name of the atomic symbol; d and the dollar signs will not appear when
@@ -3974,9 +3940,6 @@ to Z. Each letter is a legitimate atomic symbol, and therefore may be referred t
a straightforward way, without ambiguity.
The second group of legal characters consists of the digits from 0 to 9. These
must be handled with some care because if a digit is considered as an ordinary integer
-
-page 85
-
rather than a character a new nonunique object will be created corresponding to it, and
this object will not be the same as the character object for the same digit, even though
it has the same print name. Since the character-handling programs depend on the char-
@@ -4029,8 +3992,6 @@ Examples
EVAL (DOLLAR NIL) value is " $
EVAL ((PRINT PERIOD) NIL) value is ". and If. is also printed.
-page 86
-
The remaining characters are all illegal as far as the key punch is concerned. The
two characters corresponding to 12 and 72 have been reserved for end-of-file and end-
of-record, respectively, The end-of-file character has print name $EOF$ and the end-
@@ -4075,8 +4036,6 @@ whose print name is in BOFFO.
sented by the sequence of characters in BOFFO. (Positive decimal integers from
0 to 9 are converted so as to point to the corresponding character object. )
-page 87
-
5. unpack [x]: SUBR pseudo-function
This function has as argument a pointer to a full word. unpack considers
the full word to be a set of 6 BCD characters, and has as value a list of these
@@ -4115,10 +4074,9 @@ an object). There is also an object CHARCOUNT whose value is an integer object g
the column just read on the card, i. e., the column number of the character given by
CURCHAR. There are three functions which affect the value of CURCHAR:
-#### 1. startread [ ] : SUBR ps eudo-function
-startread is a function of no arguments which causes a new card to be read. The value of startread is the first character on that card, or more precisely,
-
-page 88
+1. startread [ 1: : SUBR ps eudo-function
+ startread is a function of no arguments which causes a new card to be read.
+ The value of startread is the first character on that card, or more precisely,
the object corresponding to the first character on the card. If an end-of-file
condition exists, the value of startread is $EOF$. The value of CURCHAR
@@ -4127,30 +4085,35 @@ becomes 1. Both CURCHAR and CHARCOUNT are undefined until a startread
is performed. A startread may be performed before the current card has been
completely read.
-#### 2. advance [ ] : SUBR pseudo -function
+2. advance [ 1: SUBR pseudo -function
+ advance is a function of no arguments which causes the next character to be
+ read. The value of advance is that character. After the 72nd character on the
+ card has been read, the next advance will have value $EOR$. After reading
+ $EOR$, the next advance will act like a startread, i. e., will read the first char-
+ acter of the next card unless an end-of-file condition exists. The new value of
+ CURCHAR is the same as the output of advance; executing advance also increases
+ the value of CHARCOUNT by 1. However, CHARCOUNT is undefined when
+ CURCHAR is either $EOR $ or $EOF $.
+3. endread [ 1: SUBR pseudo-function
+ endread is a function of no arguments which causes the remainder of the
+ card to be read and ignored. endread sets CURCHAR to $EOR$ and leaves
+ CHARCOUNT undefined; the value of endread is always $EOR $. An advance
+ following endread acts like a startread. If CURCHAR already has value $EOR $
+ and endread is performed, CURCHAR will remain the same and endread will,
+ as usual, have value $EOR $.
-advance is a function of no arguments which causes the next character to be read. The value of advance is that character. After the 72nd character on the card has been read, the next advance will have value $EOR$. After reading $EOR$, the next advance will act like a startread, i. e., will read the first char acter of the next card unless an end-of-file condition exists. The new value of CURCHAR is the same as the output of advance; executing advance also increases the value of CHARCOUNT by 1. However, CHARCOUNT is undefined when CURCHAR is either $EOR $ or $EOF $.
-
-#### 3. endread [ ] : SUBR pseudo-function
+Diagnostic Function
-endread is a function of no arguments which causes the remainder of the card to be read and ignored. endread sets CURCHAR to $EOR$ and leaves CHARCOUNT undefined; the value of endread is always $EOR $. An advance following endread acts like a startread. If CURCHAR already has value $EOR $ and endread is performed, CURCHAR will remain the same and endread will, as usual, have value $EOR $.
-
-### Diagnostic Function
-
-#### error 1 [ ]: SUBR pseudo-function
-
-error1 is a function of no arguments and has value NIL. It should be executed
+error 1 [ 1: SUBR pseudo-function
+errorL is a function of no arguments and has value NIL. It should be executed
only while reading characters from a card (or tape). Its effect is to mark the char-
acter just read, i. e., CURCHAR, so that when the end of the card is reached, either
by successive advances or by an endread, the entire card is printed out along with
a visual pointer to the defective character. For a line consisting of ABCDEFG fol-
lowed by blanks, a pointer to C would look like this:
-
-```
- v
+v
ABCDEFG
- A
-```
+A
If error 1 is performed an even number of times on the same character, the A will
not appear. If error1 is performed before the first startread or while CURCHAR
has value $EOR $ or $EOF $, it will have no effect. Executing a startread before
@@ -4159,27 +4122,28 @@ card is considered to have been completed when CURCHAR has been set to $EOR$.
Successive endreads will cause the error l printout to be reprinted. Any number
of characters in a given line may be marked by error1.
-page 89
-
## APPENDIX G : MEMORY ALLOCATION AND THE GARBAGE COLLECTOR
The following diagram shows the way in which space is allocated in the LISP System.
-| Address (octal) | Assigned to |
-| --------------- | ------------------------------------------------------------ |
-| 77777 | ----- |
-| | Loader |
-| 77600 | ----- |
-| | LAP |
-| | Compiler |
-| 70000 | ----- |
-| | Free storage |
-| | Full words |
-| | Pushdown list |
-| | Binary program space |
-| 17000 | |
-| | Interpreter, I/O, Read Print, Arithmetic, Overlord, Garbage Collector, and other system coding |
-| 00000 | |
+Loader
+LAP
+
+Compiler
+
+Free Storage
+
+Full Words
+
+Push-Down List
+
+Binary Program Space
+
+Interpreter, I/O, Read
+Print, Arithmetic,
+Overlord, Garbage
+Collector, and other
+system coding
The addresses in this chart are only approximate. The available space is divided
among binary program space, push-down list, full-word space, and free-storage space
@@ -4195,9 +4159,6 @@ FEXPR1s, evalquote doublets waiting to be executed, APVALts, and partial results
the computation that is in progress.
Full-word space is filled with the BCD characters of PNAMEts, the actual numbers
-
-page 90
-
of numerical atomic structures, and the TXL words of SUBRtsB FSUBRts, and SYMts.
All available words in the free-storage area that are not in use are strung together
in one long list called the free-storage list. Every time a word is needed (for example,
@@ -4232,8 +4193,6 @@ can be recognized by the stationary pattern of the MQ lights. Any trap that prev
completion of a garbage collection will create a panic condition in memory from which
there is no recovery.
-page 91
-
## APPENDIX H : RECURSION AND THE PUSH-DOWN LIST
One of the most powerful resources of the LISP language is its ability to accept
@@ -4280,9 +4239,6 @@ ter 1, to place the arguments on the push-down list, and to set up the parameter
the push-down block.
Because pointers to list structures are normally stored on the push-down list, the
-
-page 92
-
garbage collector must mark the currently active portion of the push-down list during a
garbage collection. Sometimes quantities are placed on the push- down list which should
not be marked. In this case, the sign bit must be negative. Cells on the active portion
@@ -4294,8 +4250,6 @@ list has the name of the function to which it belongs, it is possible to form a
these names. This is called the backtrace, and is normally printed out after error
diagnostics.
-page 93
-
## APPENDIX I : LISP FOR SHARE DISTRIBUTION
The Artificial Intelligence Project at Stanford University has produced a version of
@@ -4340,8 +4294,6 @@ the time spent in the packet being finished. This time printout, to be meaningfu
requires the computer to have a millisecond clock in cell 5 (RPQ F 89349, with mil-
lisecond feature).
-page 94
-
It is also possible to determine how much time is required to execute a given func-
tion. llTIMEl()lt initializes two time cells to zero and prints out, in the same format
that is used for the evalquote time printout, two times, and these are both zero.
@@ -4386,9 +4338,6 @@ after x number of function entrances. Furthermore, when the tracecount mecha-
nism has been activated, by execution of ltTRACECOUNT(x)ll, some of the blank
space in the garbage collector printout will be used to output the number of function
entrances which have taken place up to the time of the garbage collection; each time
-
-page 95
-
the arguments or value of a traced function are printed the number of function en-
trances will be printed; and if an error occurs, the number of function entrances ac-
complished before the error will be printed.
@@ -4435,9 +4384,6 @@ of LISP to communicate between different systems. The functions tape, -- rewind,
ttTAPE(s)tt, where s is a list, allows the user to specify up to ten scratch tapes;
if more than ten are specified, only the first ten are used. The value of tape is its
argument. The initial tape settings are, from one to ten, A4, A5, A6, A7, A8, B2,
-
-page 96
-
B3, B4, B5, B6. The tapes must be specified by the octal number that occurs in the
address portion of a machine-language instruction to rewind that tape; that is, a four-
digit octal number is required - the first (high-order) digit is a 1 if channel A is de-
@@ -4483,8 +4429,6 @@ Evalquote is available to the programmer as a LISP function - thus, one may now
write I1(EVALQUOTE APPEND ((A)(B C D)))I1, rather than "(EVAL (QUOTE (APPEND
(A)(B C D))) NIL)", should one desire to do so.
-page 97
-
### Backtrace
This function was copied (not quite literally) from M. I. T.'s LISP system on the
@@ -4533,9 +4477,6 @@ defined results.
For the convenience of those who find it difficult to get along with the tlCONDn form
of the conditional statement, the following "IF" forms are provided in the new system.
-
-page 98
-
"IF (a THEN b ELSE c)I1 and "IF (a b c)I1 are equivalent to nCOND ((a b)(T c))". "IF
(a THEN b)n and "IF (a b)" are equivalent to "COND ((a b))".
@@ -4577,8 +4518,6 @@ Characteristics of the System
The set-up deck supplied with the SHARE LISP system produces a system tape
with the following properties:
-page 99
-
Size (in words) -
Binary Program Space 14000 octal
Push-Down List 5000 octal
@@ -4600,9 +4539,7 @@ SW5 on to suppress SYSPOT output
SW6 on to return to overlord after accumulator printout resulting from
error *I? 5*. SW6 off for error printout.
-page 100
-
-## Index to function descriptions
+## Index
| Function | Call type | Implementation | Pages |
|--------------|------------|------------------|------------------------------|
diff --git a/doc/values.md b/doc/values.md
index 630052e..5e75113 100644
--- a/doc/values.md
+++ b/doc/values.md
@@ -1,6 +1,4 @@
-# The properties of the system, and their values
-
-## here be dragons
+# The properties of the system, and their values: here be dragons
Lisp is the list processing language; that is what its name means. It processes data structures built of lists - which may be lists of lists, or lists of numbers, or lists of any other sort of data item provided for by the designers of the system.
diff --git a/docs/cloverage/beowulf/bootstrap.clj.html b/docs/cloverage/beowulf/bootstrap.clj.html
index c45387d..20afabb 100644
--- a/docs/cloverage/beowulf/bootstrap.clj.html
+++ b/docs/cloverage/beowulf/bootstrap.clj.html
@@ -38,1237 +38,1213 @@
011 objects."
- 012 (:require [beowulf.cons-cell :refer [F make-beowulf-list make-cons-cell
+ 012 (:require [clojure.string :as s]
- 013 pretty-print T]]
+ 013 [clojure.tools.trace :refer :all]
- 014 [beowulf.host :refer [ASSOC ATOM CAAR CADAR CADDR CADR CAR CDR GET
-
-
- 015 LIST NUMBERP PAIRLIS traced?]]
-
-
- 016 [beowulf.oblist :refer [*options* NIL oblist]])
-
-
- 017 (:import [beowulf.cons_cell ConsCell]
-
-
- 018 [clojure.lang Symbol]))
+ 014 [beowulf.cons-cell :refer [make-beowulf-list make-cons-cell NIL T F]]))
- 019
+ 015
- 020 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ 016 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- 021 ;;;
+ 017 ;;;
- 022 ;;; Copyright (C) 2022-2023 Simon Brooke
+ 018 ;;; This file is essentially Lisp as defined in Chapter 1 (pages 1-14) of the
+
+
+ 019 ;;; Lisp 1.5 Programmer's Manual; that is to say, a very simple Lisp language,
+
+
+ 020 ;;; which should, I believe, be sufficient in conjunction with the functions
+
+
+ 021 ;;; provided by `beowulf.host`, be sufficient to bootstrap the full Lisp 1.5
+
+
+ 022 ;;; interpreter.
023 ;;;
- 024 ;;; This program is free software; you can redistribute it and/or
-
-
- 025 ;;; modify it under the terms of the GNU General Public License
-
-
- 026 ;;; as published by the Free Software Foundation; either version 2
-
-
- 027 ;;; of the License, or (at your option) any later version.
-
-
- 028 ;;;
-
-
- 029 ;;; This program is distributed in the hope that it will be useful,
-
-
- 030 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-
-
- 031 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-
-
- 032 ;;; GNU General Public License for more details.
-
-
- 033 ;;;
-
-
- 034 ;;; You should have received a copy of the GNU General Public License
-
-
- 035 ;;; along with this program; if not, write to the Free Software
-
-
- 036 ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
-
- 037 ;;;
-
-
- 038 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ 024 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- 039
-
-
- 040 (declare APPLY EVAL prog-eval)
-
-
- 041
-
-
- 042 ;;;; The PROGram feature ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- 043
-
-
- 044 (def find-target
+ 025
- 045 (memoize
+ 026 (declare EVAL)
+
+
+ 027
- 046 (fn [target body]
+ 028 (def oblist
-
- 047 (loop [body' body]
+
+ 029 "The default environment."
- 048 (cond
+ 030 (atom NIL))
-
- 049 (= body' NIL) (throw (ex-info (str "Mislar GO miercels: `" target "`")
+
+ 031
-
- 050 {:phase :lisp
+
+ 032 (def ^:dynamic *options*
- 051 :function 'PROG
+ 033 "Command line options from invocation."
+
+
+ 034 {})
+
+
+ 035
+
+
+ 036 (defmacro NULL
- 052 :type :lisp
+ 037 "Returns `T` if and only if the argument `x` is bound to `NIL`; else `F`."
- 053 :code :A6
+ 038 [x]
- 054 :target target}))
-
-
- 055 (= (.getCar body') target) body'
-
-
- 056 :else (recur (.getCdr body')))))))
+ 039 `(if (= ~x NIL) T F))
- 057
+ 040
-
- 058 (defn- prog-cond
+
+ 041 (defmacro ATOM
- 059 "Like `EVCON`, q.v. except using `prog-eval` instead of `EVAL` and not
+ 042 "Returns `T` if and only is the argument `x` is bound to and atom; else `F`.
- 060 throwing an error if no clause matches."
+ 043 It is not clear to me from the documentation whether `(ATOM 7)` should return
- 061 [clauses vars env depth]
+ 044 `T` or `F`. I'm going to assume `T`."
+
+
+ 045 [x]
- 062 (loop [clauses' clauses]
-
-
- 063 (if-not (= clauses' NIL)
-
-
- 064 (let [test (prog-eval (CAAR clauses') vars env depth)]
-
-
- 065 (if (not (#{NIL F} test))
-
-
- 066 (prog-eval (CADAR clauses') vars env depth)
-
-
- 067 (recur (.getCdr clauses'))))
-
-
- 068 NIL)))
+ 046 `(if (or (symbol? ~x) (number? ~x)) T F))
- 069
+ 047
-
- 070 (defn- merge-vars [vars env]
+
+ 048 (defmacro ATOM?
-
- 071 (reduce
+
+ 049 "The convention of returning `F` from predicates, rather than `NIL`, is going
+
+
+ 050 to tie me in knots. This is a variant of `ATOM` which returns `NIL`
+
+
+ 051 on failure."
+
+
+ 052 [x]
- 072 #(make-cons-cell
-
-
- 073 (make-cons-cell %2 (@vars %2))
-
-
- 074 env)
-
-
- 075 env
-
-
- 076 (keys @vars)))
+ 053 `(if (or (symbol? ~x) (number? ~x)) T NIL))
- 077
+ 054
- 078 (defn prog-eval
+ 055 (defn CAR
- 079 "Like `EVAL`, q.v., except handling symbols, and expressions starting
+ 056 "Return the item indicated by the first pointer of a pair. NIL is treated
- 080 `GO`, `RETURN`, `SET` and `SETQ` specially."
+ 057 specially: the CAR of NIL is NIL."
- 081 [expr vars env depth]
-
-
- 082 (cond
-
-
- 083 (number? expr) expr
-
-
- 084 (symbol? expr) (@vars expr)
-
-
- 085 (instance? ConsCell expr) (case (.getCar expr)
+ 058 [x]
- 086 COND (prog-cond (.getCdr expr)
-
-
- 087 vars env depth)
-
-
- 088 GO (make-cons-cell
-
-
- 089 '*PROGGO* (.getCar (.getCdr expr)))
-
-
- 090 RETURN (make-cons-cell
-
-
- 091 '*PROGRETURN*
-
-
- 092 (prog-eval (.getCar (.getCdr expr))
-
-
- 093 vars env depth))
-
-
- 094 SET (let [v (CADDR expr)]
-
-
- 095 (swap! vars
-
-
- 096 assoc
-
-
- 097 (prog-eval (CADR expr)
-
-
- 098 vars env depth)
-
-
- 099 (prog-eval (CADDR expr)
-
-
- 100 vars env depth))
-
-
- 101 v)
-
-
- 102 SETQ (let [v (CADDR expr)]
-
-
- 103 (swap! vars
-
-
- 104 assoc
-
-
- 105 (CADR expr)
-
-
- 106 (prog-eval v
-
-
- 107 vars env depth))
-
-
- 108 v)
-
-
- 109 ;; else
-
-
- 110 (beowulf.bootstrap/EVAL expr
-
-
- 111 (merge-vars vars env)
-
-
- 112 depth))))
-
-
- 113
-
-
- 114 (defn PROG
-
-
- 115 "The accursed `PROG` feature. See page 71 of the manual.
-
-
- 116
-
-
- 117 Lisp 1.5 introduced `PROG`, and most Lisps have been stuck with it ever
-
-
- 118 since. It introduces imperative programming into what should be a pure
-
-
- 119 functional language, and consequently it's going to be a pig to implement.
-
-
- 120
-
-
- 121 Broadly, `PROG` is a variadic pseudo function called as a `FEXPR` (or
-
-
- 122 possibly an `FSUBR`, although I'm not presently sure that would even work.)
-
-
- 123
-
-
- 124 The arguments, which are unevaluated, are a list of forms, the first of
-
-
- 125 which is expected to be a list of symbols which will be treated as names
-
-
- 126 of variables within the program, and the rest of which (the 'program body')
-
-
- 127 are either lists or symbols. Lists are treated as Lisp expressions which
-
-
- 128 may be evaulated in turn. Symbols are treated as targets for the `GO`
-
-
- 129 statement.
-
-
- 130
-
-
- 131 **GO:**
-
-
- 132 A `GO` statement takes the form of `(GO target)`, where
-
-
- 133 `target` should be one of the symbols which occur at top level among that
-
-
- 134 particular invocation of `PROG`s arguments. A `GO` statement may occur at
-
-
- 135 top level in a PROG, or in a clause of a `COND` statement in a `PROG`, but
-
-
- 136 not in a function called from the `PROG` statement. When a `GO` statement
-
-
- 137 is evaluated, execution should transfer immediately to the expression which
-
-
- 138 is the argument list immediately following the symbol which is its target.
-
-
- 139
-
-
- 140 If the target is not found, an error with the code `A6` should be thrown.
-
-
- 141
-
-
- 142 **RETURN:**
-
-
- 143 A `RETURN` statement takes the form `(RETURN value)`, where
-
-
- 144 `value` is any value. Following the evaluation of a `RETURN` statement,
-
-
- 145 the `PROG` should immediately exit without executing any further
-
-
- 146 expressions, returning the value.
-
-
- 147
-
-
- 148 **SET and SETQ:**
-
-
- 149 In addition to the above, if a `SET` or `SETQ` expression is encountered
-
-
- 150 in any expression within the `PROG` body, it should affect not the global
-
-
- 151 object list but instead only the local variables of the program.
-
-
- 152
-
-
- 153 **COND:**
-
-
- 154 In **strict** mode, when in normal execution, a `COND` statement none of
-
-
- 155 whose clauses match should not return `NIL` but should throw an error with
-
-
- 156 the code `A3`... *except* that inside a `PROG` body, it should not do so.
-
-
- 157 *sigh*.
-
-
- 158
-
-
- 159 **Flow of control:**
-
-
- 160 Apart from the exceptions specified above, expressions in the program body
-
-
- 161 are evaluated sequentially. If execution reaches the end of the program
-
-
- 162 body, `NIL` is returned.
-
-
- 163
-
-
- 164 Got all that?
-
-
- 165
-
-
- 166 Good."
-
-
- 167 [program env depth]
-
-
- 168 (let [trace (traced? 'PROG)
-
-
- 169 vars (atom (reduce merge (map #(assoc {} % NIL) (.getCar program))))
-
-
- 170 body (.getCdr program)
-
-
- 171 targets (set (filter symbol? body))]
-
-
- 172 (when trace (do
-
-
- 173 (println "Program:")
-
-
- 174 (pretty-print program))) ;; for debugging
-
-
- 175 (loop [cursor body]
-
-
- 176 (let [step (.getCar cursor)]
-
-
- 177 (when trace (do (println "Executing step: " step)
-
-
- 178 (println " with vars: " @vars)))
-
-
- 179 (cond (= cursor NIL) NIL
-
-
- 180 (symbol? step) (recur (.getCdr cursor))
-
-
- 181 :else (let [v (prog-eval (.getCar cursor) vars env depth)]
-
-
- 182 (when trace (println " --> " v))
-
-
- 183 (if (instance? ConsCell v)
-
-
- 184 (case (.getCar v)
-
-
- 185 *PROGGO* (let [target (.getCdr v)]
-
-
- 186 (if (targets target)
-
-
- 187 (recur (find-target target body))
-
-
- 188 (throw (ex-info (str "Uncynlic GO miercels `"
-
-
- 189 target "`")
-
-
- 190 {:phase :lisp
-
-
- 191 :function 'PROG
-
-
- 192 :args program
-
-
- 193 :type :lisp
-
-
- 194 :code :A6
-
-
- 195 :target target
-
-
- 196 :targets targets}))))
-
-
- 197 *PROGRETURN* (.getCdr v)
-
-
- 198 ;; else
-
-
- 199 (recur (.getCdr cursor)))
-
-
- 200 (recur (.getCdr cursor)))))))))
-
-
- 201
-
-
- 202 ;;;; Tracing execution ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- 203
-
-
- 204 (defn- trace-call
-
-
- 205 "Show a trace of a call to the function named by this `function-symbol`
-
-
- 206 with these `args` at this depth."
-
-
- 207 [function-symbol args depth]
+ 059 (cond
- 208 (when (traced? function-symbol)
-
-
- 209 (let [indent (apply str (repeat depth "-"))]
-
-
- 210 (println (str indent "> " function-symbol " " args)))))
-
-
- 211
-
-
- 212 (defn- trace-response
-
-
- 213 "Show a trace of this `response` from the function named by this
-
-
- 214 `function-symbol` at this depth."
-
-
- 215 [function-symbol response depth]
-
-
- 216 (when (traced? function-symbol)
-
-
- 217 (let [indent (apply str (repeat depth "-"))]
-
-
- 218 (println (str "<" indent " " function-symbol " " response))))
-
-
- 219 response)
-
-
- 220
-
-
- 221 (defn- value
-
-
- 222 "Seek a value for this symbol `s` by checking each of these indicators in
-
-
- 223 turn."
-
-
- 224 ([s]
-
-
- 225 (value s (list 'APVAL 'EXPR 'FEXPR 'SUBR 'FSUBR)))
-
-
- 226 ([s indicators]
+ 060 (= x NIL) NIL
- 227 (when (symbol? s)
+ 061 (instance? beowulf.cons_cell.ConsCell x) (.CAR x)
+
+
+ 062 :else
+
+
+ 063 (throw
+
+
+ 064 (Exception.
+
+
+ 065 (str "Cannot take CAR of `" x "` (" (.getName (.getClass x)) ")")))))
+
+
+ 066
+
+
+ 067 (defn CDR
+
+
+ 068 "Return the item indicated by the second pointer of a pair. NIL is treated
+
+
+ 069 specially: the CDR of NIL is NIL."
+
+
+ 070 [x]
+
+
+ 071 (cond
+
+
+ 072 (= x NIL) NIL
+
+
+ 073 (instance? beowulf.cons_cell.ConsCell x) (.CDR x)
+
+
+ 074 :else
+
+
+ 075 (throw
+
+
+ 076 (Exception.
+
+
+ 077 (str "Cannot take CDR of `" x "` (" (.getName (.getClass x)) ")")))))
+
+
+ 078
+
+
+ 079 (defn uaf
+
+
+ 080 "Universal access function; `l` is expected to be an arbitrary list, `path`
+
+
+ 081 a (clojure) list of the characters `a` and `d`. Intended to make declaring
+
+
+ 082 all those fiddly `#'c[ad]+r'` functions a bit easier"
+
+
+ 083 [l path]
+
+
+ 084 (cond
+
+
+ 085 (= l NIL) NIL
+
+
+ 086 (empty? path) l
+
+
+ 087 :else (case (last path)
+
+
+ 088 \a (uaf (CAR l) (butlast path))
+
+
+ 089 \d (uaf (CDR l) (butlast path)))))
+
+
+ 090
+
+
+ 091 (defn CAAR [x] (uaf x (seq "aa")))
+
+
+ 092 (defn CADR [x] (uaf x (seq "ad")))
+
+
+ 093 (defn CDDR [x] (uaf x (seq "dd")))
+
+
+ 094 (defn CDAR [x] (uaf x (seq "da")))
+
+
+ 095
+
+
+ 096 (defn CAAAR [x] (uaf x (seq "aaa")))
+
+
+ 097 (defn CAADR [x] (uaf x (seq "aad")))
+
+
+ 098 (defn CADAR [x] (uaf x (seq "ada")))
+
+
+ 099 (defn CADDR [x] (uaf x (seq "add")))
+
+
+ 100 (defn CDDAR [x] (uaf x (seq "dda")))
+
+
+ 101 (defn CDDDR [x] (uaf x (seq "ddd")))
+
+
+ 102 (defn CDAAR [x] (uaf x (seq "daa")))
+
+
+ 103 (defn CDADR [x] (uaf x (seq "dad")))
+
+
+ 104
+
+
+ 105 (defn CAAAAR [x] (uaf x (seq "aaaa")))
+
+
+ 106 (defn CAADAR [x] (uaf x (seq "aada")))
+
+
+ 107 (defn CADAAR [x] (uaf x (seq "adaa")))
+
+
+ 108 (defn CADDAR [x] (uaf x (seq "adda")))
+
+
+ 109 (defn CDDAAR [x] (uaf x (seq "ddaa")))
+
+
+ 110 (defn CDDDAR [x] (uaf x (seq "ddda")))
+
+
+ 111 (defn CDAAAR [x] (uaf x (seq "daaa")))
+
+
+ 112 (defn CDADAR [x] (uaf x (seq "dada")))
+
+
+ 113 (defn CAAADR [x] (uaf x (seq "aaad")))
+
+
+ 114 (defn CAADDR [x] (uaf x (seq "aadd")))
+
+
+ 115 (defn CADADR [x] (uaf x (seq "adad")))
+
+
+ 116 (defn CADDDR [x] (uaf x (seq "addd")))
+
+
+ 117 (defn CDDADR [x] (uaf x (seq "ddad")))
+
+
+ 118 (defn CDDDDR [x] (uaf x (seq "dddd")))
+
+
+ 119 (defn CDAADR [x] (uaf x (seq "daad")))
+
+
+ 120 (defn CDADDR [x] (uaf x (seq "dadd")))
+
+
+ 121
+
+
+ 122 (defn EQ
+
+
+ 123 "Returns `T` if and only if both `x` and `y` are bound to the same atom,
+
+
+ 124 else `F`."
+
+
+ 125 [x y]
+
+
+ 126 (if (and (= (ATOM x) T) (= x y)) T F))
+
+
+ 127
+
+
+ 128 (defn EQUAL
+
+
+ 129 "This is a predicate that is true if its two arguments are identical
+
+
+ 130 S-expressions, and false if they are different. (The elementary predicate
+
+
+ 131 `EQ` is defined only for atomic arguments.) The definition of `EQUAL` is
+
+
+ 132 an example of a conditional expression inside a conditional expression.
+
+
+ 133
+
+
+ 134 NOTE: returns `F` on failure, not `NIL`"
+
+
+ 135 [x y]
+
+
+ 136 (cond
+
+
+ 137 (= (ATOM x) T) (EQ x y)
+
+
+ 138 (= (EQUAL (CAR x) (CAR y)) T) (EQUAL (CDR x) (CDR y))
+
+
+ 139 :else F))
+
+
+ 140
+
+
+ 141 (defn SUBST
+
+
+ 142 "This function gives the result of substituting the S-expression `x` for
+
+
+ 143 all occurrences of the atomic symbol `y` in the S-expression `z`."
+
+
+ 144 [x y z]
+
+
+ 145 (cond
+
+
+ 146 (= (EQUAL y z) T) x
+
+
+ 147 (= (ATOM? z) T) z ;; NIL is a symbol
+
+
+ 148 :else
- 228 (first (remove #(= % NIL) (map #(GET s %)
-
-
- 229 indicators))))))
+ 149 (make-cons-cell (SUBST x y (CAR z)) (SUBST x y (CDR z)))))
- 230
-
-
- 231 ;;;; APPLY ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- 232
+ 150
- 233 (defn try-resolve-subroutine
+ 151 (defn APPEND
- 234 "Attempt to resolve this `subr` with these `args`."
-
-
- 235 [subr args]
-
-
- 236 (when (and subr (not= subr NIL))
-
-
- 237 (try @(resolve subr)
-
-
- 238 (catch Throwable any
-
-
- 239 (throw (ex-info "þegnung (SUBR) ne āfand"
-
-
- 240 {:phase :apply
-
-
- 241 :function subr
-
-
- 242 :args args
-
-
- 243 :type :beowulf}
-
-
- 244 any))))))
+ 152 "Append the the elements of `y` to the elements of `x`.
- 245
-
-
- 246 (defn- apply-symbolic
+ 153
- 247 "Apply this `funtion-symbol` to these `args` in this `environment` and
+ 154 All args are assumed to be `beowulf.cons-cell/ConsCell` objects.
- 248 return the result."
+ 155 See page 11 of the Lisp 1.5 Programmers Manual."
- 249 [^Symbol function-symbol args ^ConsCell environment depth]
-
-
- 250 (trace-call function-symbol args depth)
-
-
- 251 (let [lisp-fn (value function-symbol '(EXPR FEXPR))
-
-
- 252 args' (cond (= NIL args) args
-
-
- 253 (empty? args) NIL
-
-
- 254 (instance? ConsCell args) args
-
-
- 255 :else (make-beowulf-list args))
-
-
- 256 subr (value function-symbol '(SUBR FSUBR))
-
-
- 257 host-fn (try-resolve-subroutine subr args')
-
-
- 258 result (cond (and lisp-fn
-
-
- 259 (not= lisp-fn NIL)) (APPLY lisp-fn args' environment depth)
+ 156 [x y]
- 260 host-fn (try
+ 157 (cond
+
+
+ 158 (= x NIL) y
+
+
+ 159 :else
- 261 (apply host-fn (when (instance? ConsCell args') args'))
-
-
- 262 (catch Exception any
-
-
- 263 (throw (ex-info (str "Uncynlic þegnung: "
-
-
- 264 (.getMessage any))
-
-
- 265 {:phase :apply
-
-
- 266 :function function-symbol
-
-
- 267 :args args
-
-
- 268 :type :beowulf}
-
-
- 269 any))))
-
-
- 270 :else (ex-info "þegnung ne āfand"
-
-
- 271 {:phase :apply
-
-
- 272 :function function-symbol
-
-
- 273 :args args
-
-
- 274 :type :beowulf}))]
-
-
- 275 (trace-response function-symbol result depth)
-
-
- 276 result))
+ 160 (make-cons-cell (CAR x) (APPEND (CDR x) y))))
- 277
+ 161
+
+
+ 162
- 278 (defn APPLY
+ 163 (defn MEMBER
- 279 "Apply this `function` to these `arguments` in this `environment` and return
+ 164 "This predicate is true if the S-expression `x` occurs among the elements
- 280 the result.
+ 165 of the list `y`.
+
+
+ 166
- 281
+ 167 All args are assumed to be symbols or `beowulf.cons-cell/ConsCell` objects.
- 282 For bootstrapping, at least, a version of APPLY written in Clojure.
+ 168 See page 11 of the Lisp 1.5 Programmers Manual."
- 283 All args are assumed to be symbols or `beowulf.cons-cell/ConsCell` objects.
-
-
- 284 See page 13 of the Lisp 1.5 Programmers Manual."
-
-
- 285 [function args environment depth]
-
-
- 286 (trace-call 'APPLY (list function args environment) depth)
-
-
- 287 (let [result (cond
-
-
- 288 (= NIL function) (if (:strict *options*)
-
-
- 289 NIL
-
-
- 290 (throw (ex-info "NIL sí ne þegnung"
-
-
- 291 {:phase :apply
-
-
- 292 :function "NIL"
-
-
- 293 :args args
-
-
- 294 :type :beowulf})))
-
-
- 295 (= (ATOM function) T) (apply-symbolic function args environment (inc depth))
-
-
- 296 :else (case (first function)
-
-
- 297 LABEL (APPLY
-
-
- 298 (CADDR function)
-
-
- 299 args
-
-
- 300 (make-cons-cell
-
-
- 301 (make-cons-cell
-
-
- 302 (CADR function)
-
-
- 303 (CADDR function))
-
-
- 304 environment)
-
-
- 305 depth)
-
-
- 306 FUNARG (APPLY (CADR function) args (CADDR function) depth)
-
-
- 307 LAMBDA (EVAL
+ 169 [x y]
- 308 (CADDR function)
-
-
- 309 (PAIRLIS (CADR function) args environment) depth)
-
-
- 310 (throw (ex-info "Ungecnáwen wyrþan sí þegnung-weard"
-
-
- 311 {:phase :apply
-
-
- 312 :function function
-
-
- 313 :args args
-
-
- 314 :type :beowulf}))))]
+ 170 (cond
- 315 (trace-response 'APPLY result depth)
+ 171 (= y NIL) F ;; NOTE: returns F on falsity, not NIL
-
- 316 result))
-
-
- 317
-
-
- 318 ;;;; EVAL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- 319
-
-
- 320 (defn- EVCON
-
-
- 321 "Inner guts of primitive COND. All `clauses` are assumed to be
-
-
- 322 `beowulf.cons-cell/ConsCell` objects. Note that tests in Lisp 1.5
-
-
- 323 often return `F`, not `NIL`, on failure. If no clause matches,
-
-
- 324 then, strictly, we throw an error with code `:A3`.
-
-
- 325
-
-
- 326 See pages 13 and 71 of the Lisp 1.5 Programmers Manual."
-
-
- 327 [clauses env depth]
-
-
- 328 (loop [clauses' clauses]
+
+ 172 (= (EQUAL x (CAR y)) T) T
- 329 (if-not (= clauses' NIL)
+ 173 :else (MEMBER x (CDR y))))
-
- 330 (let [test (EVAL (CAAR clauses') env depth)]
-
-
- 331 (if (not (#{NIL F} test))
-
-
- 332 ;; (and (not= test NIL) (not= test F))
-
-
- 333 (EVAL (CADAR clauses') env depth)
+
+ 174
- 334 (recur (.getCdr clauses'))))
-
-
- 335 (if (:strict *options*)
-
-
- 336 (throw (ex-info "Ne ġefōg dǣl in COND"
-
-
- 337 {:phase :eval
+ 175 (defn PAIRLIS
- 338 :function 'COND
-
-
- 339 :args (list clauses)
+ 176 "This function gives the list of pairs of corresponding elements of the
- 340 :type :lisp
+ 177 lists `x` and `y`, and APPENDs this to the list `a`. The resultant list
- 341 :code :A3}))
+ 178 of pairs, which is like a table with two columns, is called an
+
+
+ 179 association list.
+
+
+ 180
+
+
+ 181 Eessentially, it builds the environment on the stack, implementing shallow
+
+
+ 182 binding.
+
+
+ 183
+
+
+ 184 All args are assumed to be `beowulf.cons-cell/ConsCell` objects.
+
+
+ 185 See page 12 of the Lisp 1.5 Programmers Manual."
+
+
+ 186 [x y a]
+
+
+ 187 (cond
+
+
+ 188 ;; the original tests only x; testing y as well will be a little more
+
+
+ 189 ;; robust if `x` and `y` are not the same length.
+
+
+ 190 (or (= NIL x) (= NIL y)) a
+
+
+ 191 :else (make-cons-cell
+
+
+ 192 (make-cons-cell (CAR x) (CAR y))
+
+
+ 193 (PAIRLIS (CDR x) (CDR y) a))))
+
+
+ 194
+
+
+ 195 (defn ASSOC
+
+
+ 196 "If a is an association list such as the one formed by PAIRLIS in the above
+
+
+ 197 example, then assoc will produce the first pair whose first term is x. Thus
+
+
+ 198 it is a table searching function.
+
+
+ 199
+
+
+ 200 All args are assumed to be `beowulf.cons-cell/ConsCell` objects.
+
+
+ 201 See page 12 of the Lisp 1.5 Programmers Manual."
+
+
+ 202 [x a]
+
+
+ 203 (cond
+
+
+ 204 (= NIL a) NIL ;; this clause is not present in the original but is added for
+
+
+ 205 ;; robustness.
+
+
+ 206 (= (EQUAL (CAAR a) x) T) (CAR a)
+
+
+ 207 :else
+
+
+ 208 (ASSOC x (CDR a))))
+
+
+ 209
+
+
+ 210 (defn- SUB2
+
+
+ 211 "Internal to `SUBLIS`, q.v., which SUBSTitutes into a list from a store.
+
+
+ 212 ? I think this is doing variable binding in the stack frame?"
+
+
+ 213 [a z]
+
+
+ 214 (cond
+
+
+ 215 (= NIL a) z
+
+
+ 216 (= (CAAR a) z) (CDAR a) ;; TODO: this looks definitely wrong
+
+
+ 217 :else
+
+
+ 218 (SUB2 (CDR a) z)))
+
+
+ 219
+
+
+ 220 (defn SUBLIS
+
+
+ 221 "Here `a` is assumed to be an association list of the form
+
+
+ 222 `((ul . vl)...(un . vn))`, where the `u`s are atomic, and `y` is any
+
+
+ 223 S-expression. What `SUBLIS` does, is to treat the `u`s as variables when
+
+
+ 224 they occur in `y`, and to SUBSTitute the corresponding `v`s from the pair
+
+
+ 225 list.
+
+
+ 226
+
+
+ 227 My interpretation is that this is variable binding in the stack frame.
+
+
+ 228
+
+
+ 229 All args are assumed to be `beowulf.cons-cell/ConsCell` objects.
+
+
+ 230 See page 12 of the Lisp 1.5 Programmers Manual."
+
+
+ 231 [a y]
+
+
+ 232 (cond
+
+
+ 233 (= (ATOM? y) T) (SUB2 a y)
+
+
+ 234 :else
+
+
+ 235 (make-cons-cell (SUBLIS a (CAR y)) (SUBLIS a (CDR y)))))
+
+
+ 236
+
+
+ 237 (defn interop-interpret-q-name
+
+
+ 238 "For interoperation with Clojure, it will often be necessary to pass
+
+
+ 239 qualified names that are not representable in Lisp 1.5. This function
+
+
+ 240 takes a sequence in the form `(PART PART PART... NAME)` and returns
+
+
+ 241 a symbol in the form `PART.PART.PART/NAME`. This symbol will then be
+
+
+ 242 tried in both that form and lower-cased. Names with hyphens or
+
+
+ 243 underscores cannot be represented with this scheme."
+
+
+ 244 [l]
- 342 NIL))))
+ 245 (if
+
+
+ 246 (seq? l)
+
+
+ 247 (symbol
+
+
+ 248 (s/reverse
+
+
+ 249 (s/replace-first
+
+
+ 250 (s/reverse
+
+
+ 251 (s/join "." (map str l)))
+
+
+ 252 "."
+
+
+ 253 "/")))
+
+
+ 254 l))
- 343
+ 255
-
- 344 (defn- EVLIS
+
+ 256 (deftrace INTEROP
- 345 "Map `EVAL` across this list of `args` in the context of this
+ 257 "Clojure (or other host environment) interoperation API. `fn-symbol` is expected
- 346 `env`ironment.All args are assumed to be `beowulf.cons-cell/ConsCell` objects.
-
-
- 347 See page 13 of the Lisp 1.5 Programmers Manual."
-
-
- 348 [args env depth]
-
-
- 349 (cond
-
-
- 350 (= NIL args) NIL
-
-
- 351 :else
-
-
- 352 (make-cons-cell
-
-
- 353 (EVAL (CAR args) env depth)
-
-
- 354 (EVLIS (CDR args) env depth))))
+ 258 to be either
- 355
-
-
- 356 (defn- eval-symbolic
+ 259
- 357 [expr env depth]
+ 260 1. a symbol bound in the host environment to a function; or
-
- 358 (let [v (ASSOC expr env)
+
+ 261 2. a sequence (list) of symbols forming a qualified path name bound to a
-
- 359 indent (apply str (repeat depth "-"))]
+
+ 262 function.
-
- 360 (when (traced? 'EVAL)
+
+ 263
-
- 361 (println (str indent ": EVAL: sceald bindele: " (or v "nil"))))
+
+ 264 Lower case characters cannot normally be represented in Lisp 1.5, so both the
-
- 362 (if (instance? ConsCell v)
+
+ 265 upper case and lower case variants of `fn-symbol` will be tried. If the
+
+
+ 266 function you're looking for has a mixed case name, that is not currently
+
+
+ 267 accessible.
+
+
+ 268
+
+
+ 269 `args` is expected to be a Lisp 1.5 list of arguments to be passed to that
+
+
+ 270 function. Return value must be something acceptable to Lisp 1.5, so either
+
+
+ 271 a symbol, a number, or a Lisp 1.5 list.
+
+
+ 272
+
+
+ 273 If `fn-symbol` is not found (even when cast to lower case), or is not a function,
+
+
+ 274 or the value returned cannot be represented in Lisp 1.5, an exception is thrown
+
+
+ 275 with `:cause` bound to `:interop` and `:detail` set to a value representing the
+
+
+ 276 actual problem."
+
+
+ 277 [fn-symbol args]
+
+
+ 278 (let
+
+
+ 279 [q-name (if
+
+
+ 280 (seq? fn-symbol)
+
+
+ 281 (interop-interpret-q-name fn-symbol)
+
+
+ 282 fn-symbol)
+
+
+ 283 l-name (symbol (s/lower-case q-name))
+
+
+ 284 f (cond
+
+
+ 285 (try
+
+
+ 286 (fn? (eval l-name))
+
+
+ 287 (catch java.lang.ClassNotFoundException e nil)) (eval l-name)
+
+
+ 288 (try
+
+
+ 289 (fn? (eval q-name))
+
+
+ 290 (catch java.lang.ClassNotFoundException e nil)) (eval q-name)
+
+
+ 291 :else (throw
+
+
+ 292 (ex-info
+
+
+ 293 (str "INTEROP: unknown function `" fn-symbol "`")
+
+
+ 294 {:cause :interop
+
+
+ 295 :detail :not-found
+
+
+ 296 :name fn-symbol
+
+
+ 297 :also-tried l-name})))
+
+
+ 298 result (eval (cons f args))]
+
+
+ 299 (cond
+
+
+ 300 (instance? beowulf.cons_cell.ConsCell result) result
+
+
+ 301 (seq? result) (make-beowulf-list result)
+
+
+ 302 (symbol? result) result
+
+
+ 303 (string? result) (symbol result)
+
+
+ 304 (number? result) result
+
+
+ 305 :else (throw
+
+
+ 306 (ex-info
+
+
+ 307 (str "INTEROP: Cannot return `" result "` to Lisp 1.5.")
+
+
+ 308 {:cause :interop
+
+
+ 309 :detail :not-representable
+
+
+ 310 :result result})))))
+
+
+ 311
- 363 (.getCdr v)
+ 312 (defn APPLY
-
- 364 (let [v' (value expr (list 'APVAL))]
+
+ 313 "For bootstrapping, at least, a version of APPLY written in Clojure.
-
- 365 (when (traced? 'EVAL)
+
+ 314 All args are assumed to be symbols or `beowulf.cons-cell/ConsCell` objects.
+
+
+ 315 See page 13 of the Lisp 1.5 Programmers Manual."
+
+
+ 316 [function args environment]
+
+
+ 317 (cond
+
+
+ 318 (=
+
+
+ 319 (ATOM? function)
+
+
+ 320 T)(cond
+
+
+ 321 ;; TODO: doesn't check whether `function` is bound in the environment;
+
+
+ 322 ;; we'll need that before we can bootstrap.
+
+
+ 323 (= function 'CAR) (CAAR args)
+
+
+ 324 (= function 'CDR) (CDAR args)
+
+
+ 325 (= function 'CONS) (make-cons-cell (CAR args) (CADR args))
+
+
+ 326 (= function 'ATOM) (if (ATOM? (CAR args)) T NIL)
- 366 (println (str indent ": EVAL: deóp bindele: (" expr " . " (or v' "nil") ")")))
+ 327 (= function 'EQ) (if (= (CAR args) (CADR args)) T NIL)
-
- 367 (if v'
+
+ 328 :else
-
- 368 v'
+
+ 329 (APPLY
- 369 (throw (ex-info "Ne tácen-bindele āfand"
-
-
- 370 {:phase :eval
-
-
- 371 :function 'EVAL
-
-
- 372 :args (list expr env depth)
-
-
- 373 :type :lisp
-
-
- 374 :code :A8})))))))
-
-
- 375
-
-
- 376 (defn EVAL
-
-
- 377 "Evaluate this `expr` and return the result. If `environment` is not passed,
-
-
- 378 it defaults to the current value of the global object list. The `depth`
-
-
- 379 argument is part of the tracing system and should not be set by user code.
-
-
- 380
-
-
- 381 All args are assumed to be numbers, symbols or `beowulf.cons-cell/ConsCell`
-
-
- 382 objects. However, if called with just a single arg, `expr`, I'll assume it's
-
-
- 383 being called from the Clojure REPL and will coerce the `expr` to `ConsCell`."
-
-
- 384 ([expr]
-
-
- 385 (let [expr' (if (and (coll? expr) (not (instance? ConsCell expr)))
-
-
- 386 (make-beowulf-list expr)
-
-
- 387 expr)]
-
-
- 388 (EVAL expr' NIL 0)))
-
-
- 389 ([expr env depth]
-
-
- 390 (trace-call 'EVAL (list expr env depth) depth)
-
-
- 391 (let [result (cond
-
-
- 392 (= NIL expr) NIL ;; it was probably a mistake to make Lisp
-
-
- 393 ;; NIL distinct from Clojure nil
-
-
- 394 (= (NUMBERP expr) T) expr
-
-
- 395 (symbol? expr) (eval-symbolic expr env depth)
-
-
- 396 (string? expr) (if (:strict *options*)
+ 330 (EVAL function environment)
- 397 (throw
-
-
- 398 (ex-info
-
-
- 399 (str "EVAL: strings not allowed in strict mode: \"" expr "\"")
-
-
- 400 {:phase :eval
-
-
- 401 :detail :strict
+ 331 args
- 402 :expr expr}))
+ 332 environment))
+
+
+ 333 (= (first function) 'LAMBDA) (EVAL
- 403 (symbol expr))
-
-
- 404 (= (ATOM (CAR expr)) T) (case (CAR expr)
-
-
- 405 COND (EVCON (CDR expr) env depth)
-
-
- 406 FUNCTION (LIST 'FUNARG (CADR expr))
-
-
- 407 PROG (PROG (CDR expr) env depth)
-
-
- 408 QUOTE (CADR expr)
-
-
- 409 ;; else
-
-
- 410 (APPLY
-
-
- 411 (CAR expr)
-
-
- 412 (EVLIS (CDR expr) env depth)
-
-
- 413 env
-
-
- 414 depth))
-
-
- 415 :else (APPLY
-
-
- 416 (CAR expr)
+ 334 (CADDR function)
- 417 (EVLIS (CDR expr) env depth)
+ 335 (PAIRLIS (CADR function) args environment))
+
+
+ 336 (= (first function) 'LABEL) (APPLY
+
+
+ 337 (CADDR function)
- 418 env
+ 338 args
- 419 depth))]
+ 339 (make-cons-cell
-
- 420 (trace-response 'EVAL result depth)
+
+ 340 (make-cons-cell
-
- 421 result)))
+
+ 341 (CADR function)
+
+
+ 342 (CADDR function))
+
+
+ 343 environment))))
- 422
+ 344
+
+
+ 345 (defn- EVCON
+
+
+ 346 "Inner guts of primitive COND. All args are assumed to be
+
+
+ 347 `beowulf.cons-cell/ConsCell` objects.
+
+
+ 348 See page 13 of the Lisp 1.5 Programmers Manual."
+
+
+ 349 [clauses env]
+
+
+ 350 (if
+
+
+ 351 (not= (EVAL (CAAR clauses) env) NIL)
+
+
+ 352 (EVAL (CADAR clauses) env)
+
+
+ 353 (EVCON (CDR clauses) env)))
+
+
+ 354
+
+
+ 355 (defn- EVLIS
+
+
+ 356 "Map `EVAL` across this list of `args` in the context of this
+
+
+ 357 `env`ironment.All args are assumed to be `beowulf.cons-cell/ConsCell` objects.
+
+
+ 358 See page 13 of the Lisp 1.5 Programmers Manual."
+
+
+ 359 [args env]
+
+
+ 360 (cond
+
+
+ 361 (= NIL args) NIL
+
+
+ 362 :else
+
+
+ 363 (make-cons-cell
+
+
+ 364 (EVAL (CAR args) env)
+
+
+ 365 (EVLIS (CDR args) env))))
+
+
+ 366
+
+
+ 367 (deftrace traced-eval
+
+
+ 368 "Essentially, identical to EVAL except traced."
+
+
+ 369 [expr env]
+
+
+ 370 (cond
+
+
+ 371 (=
+
+
+ 372 (ATOM? expr) T)
+
+
+ 373 (CDR (ASSOC expr env))
+
+
+ 374 (=
+
+
+ 375 (ATOM? (CAR expr))
+
+
+ 376 T)(cond
+
+
+ 377 (= (CAR expr) 'QUOTE) (CADR expr)
+
+
+ 378 (= (CAR expr) 'COND) (EVCON (CDR expr) env)
+
+
+ 379 :else (APPLY
+
+
+ 380 (CAR expr)
+
+
+ 381 (EVLIS (CDR expr) env)
+
+
+ 382 env))
+
+
+ 383 :else (APPLY
+
+
+ 384 (CAR expr)
+
+
+ 385 (EVLIS (CDR expr) env)
+
+
+ 386 env)))
+
+
+ 387
+
+
+ 388 (defn EVAL
+
+
+ 389 "For bootstrapping, at least, a version of EVAL written in Clojure.
+
+
+ 390 All args are assumed to be symbols or `beowulf.cons-cell/ConsCell` objects.
+
+
+ 391 See page 13 of the Lisp 1.5 Programmers Manual."
+
+
+ 392 [expr env]
+
+
+ 393 (cond
+
+
+ 394 (true? (:trace *options*))
+
+
+ 395 (traced-eval expr env)
+
+
+ 396 (=
+
+
+ 397 (ATOM? expr) T)
+
+
+ 398 (CDR (ASSOC expr env))
+
+
+ 399 (=
+
+
+ 400 (ATOM? (CAR expr))
+
+
+ 401 T)(cond
+
+
+ 402 (= (CAR expr) 'QUOTE) (CADR expr)
+
+
+ 403 (= (CAR expr) 'COND) (EVCON (CDR expr) env)
+
+
+ 404 :else (APPLY
+
+
+ 405 (CAR expr)
+
+
+ 406 (EVLIS (CDR expr) env)
+
+
+ 407 env))
+
+
+ 408 :else (APPLY
+
+
+ 409 (CAR expr)
+
+
+ 410 (EVLIS (CDR expr) env)
+
+
+ 411 env)))
+
+
+ 412
+
+
+ 413
+
+
+ 414