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. -![Beowulf logo](https://simon-brooke.github.io/beowulf/docs/img/beowulf_logo_med.png) - -## 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. **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  
diff --git a/docs/cloverage/beowulf/cons_cell.clj.html b/docs/cloverage/beowulf/cons_cell.clj.html index a229691..5a58211 100644 --- a/docs/cloverage/beowulf/cons_cell.clj.html +++ b/docs/cloverage/beowulf/cons_cell.clj.html @@ -11,820 +11,466 @@ 002    "The fundamental cons cell on which all Lisp structures are built.

- 003    Lisp 1.5 lists do not necessarily have a sequence as their CDR, and + 003    Lisp 1.5 lists do not necessarily have a sequence as their CDR, so
- 004    must have both CAR and CDR mutable, so cannot be implemented on top -
- - 005    of Clojure lists." -
- - 006    (:require [beowulf.oblist :refer [NIL]])) + 004    cannot be implemented on top of Clojure lists.")
- 007   + 005   +
+ + 006  (def NIL
- 008  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + 007    "The canonical empty list symbol."
- - 009  ;;; -
- - 010  ;;; Copyright (C) 2022-2023 Simon Brooke -
- - 011  ;;; -
- - 012  ;;; This program is free software; you can redistribute it and/or -
- - 013  ;;; modify it under the terms of the GNU General Public License -
- - 014  ;;; as published by the Free Software Foundation; either version 2 -
- - 015  ;;; of the License, or (at your option) any later version. -
- - 016  ;;;  -
- - 017  ;;; This program is distributed in the hope that it will be useful, -
- - 018  ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -
- - 019  ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -
- - 020  ;;; GNU General Public License for more details. -
- - 021  ;;;  -
- - 022  ;;; You should have received a copy of the GNU General Public License -
- - 023  ;;; along with this program; if not, write to the Free Software -
- - 024  ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. -
- - 025  ;;; -
- - 026  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + 008    (symbol "NIL"))
- 027   + 009   +
+ + 010  (def T +
+ + 011    "The canonical true value." +
+ + 012    (symbol "T")) ;; true. +
+ + 013   +
+ + 014  (def F +
+ + 015    "The canonical false value - different from `NIL`, which is not canonically +
+ + 016    false in Lisp 1.5." +
+ + 017    (symbol "F")) ;; false as distinct from nil +
+ + 018   +
+ + 019  (deftype ConsCell [CAR CDR] +
+ + 020    clojure.lang.ISeq +
+ + 021    (cons [this x] (ConsCell. x this)) +
+ + 022    (first [this] (.CAR this)) +
+ + 023    ;; next and more must return ISeq: +
+ + 024    ;; https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/ISeq.java +
+ + 025    (more [this] (if +
+ + 026                   (seq? (.CDR this)) +
+ + 027                   (.CDR this) +
+ + 028                   clojure.lang.PersistentList/EMPTY)) +
+ + 029    (next [this] (if +
+ + 030                   (seq? (.CDR this)) +
+ + 031                   (.CDR this) +
+ + 032                   nil ;; next returns nil when empty +
+ + 033                   )) +
+ + 034   +
+ + 035    clojure.lang.Seqable +
+ + 036    (seq [this] this) +
+ + 037   +
+ + 038    ;; for some reason this marker protocol is needed otherwise compiler complains +
+ + 039    ;; that `nth not supported on ConsCell` +
+ + 040    clojure.lang.Sequential +
+ + 041   +
+ + 042    clojure.lang.IPersistentCollection +
+ + 043    (count [this] (if +
+ + 044                    (coll? (.CDR this)) +
+ + 045                    (inc (.count (.CDR this))) +
+ + 046                    1)) +
+ + 047    (empty [this] false) ;; a cons cell is by definition not empty. +
+ + 048    (equiv [this other] (if +
+ + 049                          (seq? other) +
+ + 050                          (and +
+ + 051                            (if +
+ + 052                              (and +
+ + 053                                (seq? (first this)) +
+ + 054                                (seq? (first other))) +
+ + 055                              (.equiv (first this) (first other)) +
+ + 056                              (= (first this) (first other))) +
+ + 057                            (if +
+ + 058                              (and +
+ + 059                                (seq? (rest this)) +
+ + 060                                (seq? (rest other))) +
+ + 061                              (.equiv (rest this) (rest other)) +
+ + 062                              (= (rest this) (rest other)))) +
+ + 063                          false))) +
+ + 064  
- 028  (declare cons-cell?) -
- - 029   -
- - 030  (def T + 065  (defn- to-string
- 031    "The canonical true value." -
- - 032    (symbol "T")) ;; true. -
- - 033   -
- - 034  (def F + 066    "Printing ConsCells gave me a *lot* of trouble. This is an internal function
- 035    "The canonical false value - different from `NIL`, which is not canonically + 067    used by the print-method override (below) in order that the standard Clojure
- 036    false in Lisp 1.5." -
- - 037    (symbol "F")) ;; false as distinct from nil -
- - 038   + 068    `print` and `str` functions will print ConsCells correctly. The argument
- 039  ;;;; The actual cons-cell ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 040   -
- - 041  (defprotocol MutableSequence + 069    `cell` must, obviously, be an instance of `ConsCell`."
- 042    "Like a sequence, but mutable." -
- - 043    (rplaca -
- - 044      [this value] -
- - 045      "replace the first element of this sequence with this value") -
- - 046    (rplacd -
- - 047      [this value] -
- - 048      "replace the rest (but-first; cdr) of this sequence with this value") -
- - 049    (getCar -
- - 050      [this] -
- - 051      "Return the first element of this sequence.") -
- - 052    (getCdr -
- - 053      [this] -
- - 054      "like `more`, q.v., but returns List `NIL` not Clojure `nil` when empty.") -
- - 055    (getUid -
- - 056      [this] -
- - 057      "Returns a unique identifier for this object")) -
- - 058   -
- - 059  (deftype ConsCell [^:unsynchronized-mutable CAR ^:unsynchronized-mutable CDR uid] -
- - 060    ;; Note that, because the CAR and CDR fields are unsynchronised mutable - i.e. -
- - 061    ;; plain old Java instance variables which can be written as well as read - -
- - 062    ;; ConsCells are NOT thread safe. This does not matter, since Lisp 1.5 is -
- - 063    ;; single threaded. -
- - 064    MutableSequence -
- - 065   -
- - 066    (rplaca [this value] -
- - 067      (if -
- - 068       (or + 070    [cell]
- 069        (satisfies? MutableSequence value) ;; can't reference + 071    (loop [c cell
- 070                ;; beowulf.cons_cell.ConsCell, + 072           n 0
- 071                ;; because it is not yet -
- - 072                ;; defined -
- - 073        (cons-cell? value) -
- - 074        (number? value) -
- - 075        (symbol? value)) + 073           s "("]
- 076        (do -
- - 077          (set! (. this CAR) value) -
- - 078          this) -
- - 079        (throw (ex-info -
- - 080                (str "Uncynlic miercels in RPLACA: `" value "` (" (type value) ")") -
- - 081                {:cause  :bad-value -
- - 082                 :detail :rplaca})))) -
- - 083   -
- - 084    (rplacd [this value] -
- - 085      (if -
- - 086       (or + 074      (if
- 087        (satisfies? MutableSequence value) -
- - 088        (cons-cell? value) -
- - 089        (number? value) + 075        (instance? beowulf.cons_cell.ConsCell c)
- 090        (symbol? value)) + 076        (let [car (.CAR c)
- 091        (do + 077              cdr (.CDR c) +
+ + 078              cons? (instance? beowulf.cons_cell.ConsCell cdr)
- 092          (set! (. this CDR) value) + 079              ss (str
- 093          this) -
- - 094        (throw (ex-info -
- - 095                (str "Uncynlic miercels in RPLACD: `" value "` (" (type value) ")") -
- - 096                {:cause  :bad-value -
- - 097                 :detail :rplaca})))) -
- - 098   -
- - 099    (getCar [this] -
- - 100      (. this CAR)) -
- - 101    (getCdr [this] -
- - 102      (. this CDR)) -
- - 103    (getUid [this] -
- - 104      (. this uid)) -
- - 105   -
- - 106    clojure.lang.ISeq -
- - 107    (cons [this x] (ConsCell. x this (gensym "c"))) -
- - 108    (first [this] (.CAR this)) -
- - 109    ;; next and more must return ISeq: -
- - 110    ;; https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/ISeq.java -
- - 111    (more [this] (if + 080                   s
- 112                  (seq? (.getCdr this)) -
- - 113                   (.getCdr this) -
- - 114                   clojure.lang.PersistentList/EMPTY)) -
- - 115    (next [this] (if -
- - 116                  (seq? (.getCdr this)) -
- - 117                   (.getCdr this) -
- - 118                   nil ;; next returns nil when empty -
- - 119                   )) -
- - 120   -
- - 121    clojure.lang.Seqable -
- - 122    (seq [this] this) -
- - 123   -
- - 124    ;; for some reason this marker protocol is needed otherwise compiler complains -
- - 125    ;; that `nth not supported on ConsCell` -
- - 126    clojure.lang.Sequential -
- - 127   -
- - 128    clojure.lang.IPersistentCollection -
- - 129    (empty [this] (= this NIL)) ;; a cons cell is by definition not empty. -
- - 130    (equiv [this other] (if -
- - 131                         (seq? other) -
- - 132                          (and -
- - 133                           (if + 081                   (to-string car)
- 134                            (and + 082                   (cond
- - 135                             (seq? (first this)) + + 083                     cons?
- - 136                             (seq? (first other))) + + 084                     " " +
+ + 085                     (or (nil? cdr) (= cdr 'NIL)) +
+ + 086                     ")" +
+ + 087                     :else
- 137                             (.equiv (first this) (first other)) + 088                     (str " . " (to-string cdr) ")")))]
- - 138                             (= (first this) (first other))) + + 089          (if
- - 139                           (if + + 090            cons?
- - 140                            (and + + 091            (recur cdr (inc n) ss) +
+ + 092            ss))
- 141                             (seq? (.getCdr this)) -
- - 142                             (seq? (.getCdr other))) -
- - 143                             (.equiv (.getCdr this) (.getCdr other)) -
- - 144                             (= (.getCdr this) (.getCdr other)))) -
- - 145                          false)) + 093        (str c))))
- 146   + 094   +
+ + 095  (defn pretty-print
- 147    clojure.lang.Counted + 096    "This isn't the world's best pretty printer but it sort of works." +
+ + 097    ([^beowulf.cons_cell.ConsCell cell] +
+ + 098     (println (pretty-print cell 80 0))) +
+ + 099    ([^beowulf.cons_cell.ConsCell cell width level]
- 148    (count [this] (loop [cell this -
- - 149                         result 1] -
- - 150                    (if -
- - 151                     (and (coll? (.getCdr cell)) (not= NIL (.getCdr cell))) -
- - 152                      (recur (.getCdr cell) (inc result)) -
- - 153                      result))) -
- - 154   -
- - 155    java.lang.Object -
- - 156    (toString [this] + 100     (loop [c cell
- 157      (str "(" + 101            n (inc level) +
+ + 102            s "("]
- 158           (. this CAR) + 103       (if
- 159           (cond -
- - 160             (instance? ConsCell (. this CDR)) (str " " (subs (.toString (. this CDR)) 1)) -
- - 161             (= NIL (. this CDR)) ")" -
- - 162             :else (str " . " (. this CDR) ")"))))) -
- - 163   -
- - 164  ;;;; Printing. Here be dragons! ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 165   -
- - 166  (defn- to-string -
- - 167    "Printing ConsCells gave me a *lot* of trouble. This is an internal function -
- - 168    used by the print-method override (below) in order that the standard Clojure -
- - 169    `print` and `str` functions will print ConsCells correctly. The argument -
- - 170    `cell` must, obviously, be an instance of `ConsCell`." -
- - 171    ;; TODO: I am deeply suspicious both of this and the defmethod which depends  -
- - 172    ;; on it. I *think* they are implicated in the `COPY` bug. If the `toString` -
- - 173    ;; override in `ConsCell` was right, neither of these would be necessary. -
- - 174    ;; see https://github.com/simon-brooke/beowulf/issues/5 -
- - 175    [cell] -
- - 176    (loop [c cell -
- - 177           n 0 -
- - 178           s "("] -
- - 179      (if -
- - 180       (instance? beowulf.cons_cell.ConsCell c) -
- - 181        (let [car (.first c) -
- - 182              cdr (.getCdr c) -
- - 183              cons? (and -
- - 184                     (instance? beowulf.cons_cell.ConsCell cdr) -
- - 185                     (not (nil? cdr)) -
- - 186                     (not= cdr NIL)) -
- - 187              ss (str -
- - 188                  s -
- - 189                  (to-string car) -
- - 190                  (cond -
- - 191                    (or (nil? cdr) (= cdr NIL)) ")" -
- - 192                    cons?  " " -
- - 193                    :else (str " . " (to-string cdr) ")")))] -
- - 194          (if -
- - 195           cons? -
- - 196            (recur cdr (inc n) ss) -
- - 197            ss)) -
- - 198        (str c)))) -
- - 199   -
- - 200  (defmethod clojure.core/print-method -
- - 201    ;;; I have not worked out how to document defmethod without blowing up the world. -
- - 202    beowulf.cons_cell.ConsCell -
- - 203    [this writer] -
- - 204    (.write writer (to-string this))) -
- - 205   -
- - 206  (defn pretty-print -
- - 207    "This isn't the world's best pretty printer but it sort of works." -
- - 208    ([cell] -
- - 209     (println (pretty-print cell 80 0))) -
- - 210    ([cell width level] -
- - 211     (loop [c cell -
- - 212            n (inc level) -
- - 213            s "("] -
- - 214       (if -
- - 215        (instance? beowulf.cons_cell.ConsCell c) -
- - 216         (let [car (.first c) -
- - 217               cdr (.getCdr c) -
- - 218               tail? (instance? beowulf.cons_cell.ConsCell cdr) -
- - 219               print-width (count (print-str c)) -
- - 220               indent (apply str (repeat n "  ")) -
- - 221               ss (str -
- - 222                   s -
- - 223                   (pretty-print car width n) -
- - 224                   (cond -
- - 225                     (or (nil? cdr) (= cdr NIL)) -
- - 226                     ")" -
- - 227                     tail? -
- - 228                     (if -
- - 229                      (< (+ (count indent) print-width) width) -
- - 230                       " " -
- - 231                       (str "\n" indent)) -
- - 232                     :else -
- - 233                     (str " . " (pretty-print cdr width n) ")")))] -
- - 234           (if -
- - 235            tail? -
- - 236             (recur cdr n ss) -
- - 237             ss)) -
- - 238         (str c))))) -
- - 239   -
- - 240  (defn cons-cell? -
- - 241    "Is this object `o` a beowulf cons-cell?" -
- - 242    [o] -
- - 243    (instance? beowulf.cons_cell.ConsCell o)) -
- - 244   -
- - 245  (defn make-cons-cell -
- - 246    "Construct a new instance of cons cell with this `car` and `cdr`." -
- - 247    [car cdr] -
- - 248    (try -
- - 249      (ConsCell. car cdr (gensym "c")) -
- - 250      (catch Exception any -
- - 251        (throw (ex-info "Ne meahte cræfte cons cell" {:car car + 104         (instance? beowulf.cons_cell.ConsCell c)
- 252                                                         :cdr cdr} any))))) -
- - 253   -
- - 254  (defn make-beowulf-list -
- - 255    "Construct a linked list of cons cells with the same content as the -
- - 256    sequence `x`." -
- - 257    [x] -
- - 258    (try -
- - 259      (cond -
- - 260        (empty? x) NIL -
- - 261        (instance? ConsCell x) (make-cons-cell (.getCar x) (.getCdr x)) -
- - 262        (coll? x) (ConsCell. -
- - 263                   (if -
- - 264                    (coll? (first x)) -
- - 265                     (make-beowulf-list (first x)) -
- - 266                     (first x)) -
- - 267                   (make-beowulf-list (rest x)) -
- - 268                   (gensym "c")) -
- - 269        :else + 105         (let [car (.CAR c)
- 270        NIL) -
- - 271      (catch Exception any + 106               cdr (.CDR c)
- 272        (throw (ex-info "Ne meahte cræfte Beowulf líste" + 107               cons? (instance? beowulf.cons_cell.ConsCell cdr)
- - 273                        {:content x} + + 108               print-width (count (print-str c)) +
+ + 109               indent (apply str (repeat n "  ")) +
+ + 110               ss (str
- 274                        any))))) + 111                    s +
+ + 112                    (pretty-print car width n) +
+ + 113                    (cond +
+ + 114                      cons? +
+ + 115                      (if +
+ + 116                        (< (+ (count indent) print-width) width) +
+ + 117                        " " +
+ + 118                        (str "\n" indent)) +
+ + 119                      (or (nil? cdr) (= cdr 'NIL)) +
+ + 120                      ")" +
+ + 121                      :else +
+ + 122                      (str " . " (pretty-print cdr width n) ")")))] +
+ + 123           (if +
+ + 124             cons? +
+ + 125             (recur cdr n ss) +
+ + 126             ss)) +
+ + 127         (str c))))) +
+ + 128   +
+ + 129   +
+ + 130   +
+ + 131  (defmethod clojure.core/print-method +
+ + 132    ;;; I have not worked out how to document defmethod without blowing up the world. +
+ + 133    beowulf.cons_cell.ConsCell +
+ + 134    [this writer] +
+ + 135    (.write writer (to-string this))) +
+ + 136   +
+ + 137   +
+ + 138  (defmacro make-cons-cell +
+ + 139    "Construct a new instance of cons cell with this `car` and `cdr`." +
+ + 140    [car cdr] +
+ + 141    `(ConsCell. ~car ~cdr)) +
+ + 142   +
+ + 143  (defn make-beowulf-list +
+ + 144    "Construct a linked list of cons cells with the same content as the +
+ + 145    sequence `x`." +
+ + 146    [x] +
+ + 147    (cond +
+ + 148      (empty? x) NIL +
+ + 149      (coll? x) (ConsCell. +
+ + 150                  (if +
+ + 151                    (seq? (first x)) +
+ + 152                    (make-beowulf-list (first x)) +
+ + 153                    (first x)) +
+ + 154                  (make-beowulf-list (rest x))) +
+ + 155      :else +
+ + 156      NIL))
diff --git a/docs/cloverage/beowulf/core.clj.html b/docs/cloverage/beowulf/core.clj.html index 209aa59..13189d9 100644 --- a/docs/cloverage/beowulf/core.clj.html +++ b/docs/cloverage/beowulf/core.clj.html @@ -11,394 +11,238 @@ 002    "Essentially, the `-main` function and the bootstrap read-eval-print loop."

- 003    (:require [beowulf.bootstrap :refer [EVAL]] + 003    (:require [beowulf.bootstrap :refer [EVAL oblist *options*]]
- 004              [beowulf.io :refer [default-sysout SYSIN]] + 004              [beowulf.read :refer [READ]]
- 005              [beowulf.oblist :refer [*options* NIL]] + 005              [clojure.java.io :as io]
- 006              [beowulf.read :refer [READ read-from-console]] + 006              [clojure.pprint :refer [pprint]]
- 007              [clojure.java.io :as io] + 007              [clojure.tools.cli :refer [parse-opts]]
- 008              [clojure.pprint :refer [pprint]] + 008              [environ.core :refer [env]])
- 009              [clojure.string :refer [trim]] -
- - 010              [clojure.tools.cli :refer [parse-opts]]) -
- - 011    (:gen-class)) + 009    (:gen-class))
- 012   -
- - 013  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 014  ;;; -
- - 015  ;;; Copyright (C) 2022-2023 Simon Brooke -
- - 016  ;;; -
- - 017  ;;; This program is free software; you can redistribute it and/or -
- - 018  ;;; modify it under the terms of the GNU General Public License -
- - 019  ;;; as published by the Free Software Foundation; either version 2 -
- - 020  ;;; of the License, or (at your option) any later version. -
- - 021  ;;;  -
- - 022  ;;; This program is distributed in the hope that it will be useful, -
- - 023  ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -
- - 024  ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -
- - 025  ;;; GNU General Public License for more details. -
- - 026  ;;;  -
- - 027  ;;; You should have received a copy of the GNU General Public License -
- - 028  ;;; along with this program; if not, write to the Free Software -
- - 029  ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. -
- - 030  ;;; -
- - 031  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 032   -
- - 033  (def stop-word  -
- - 034    "The word which, if submitted an an input line, will cause Beowulf to quit. -
- - 035     Question: should this be `forlǣte`?" -
- - 036    "STOP") -
- - 037   + 010  
- 038  (def cli-options -
- - 039    [["-f FILEPATH" "--file-path FILEPATH" -
- - 040      "Set the path to the directory for reading and writing Lisp files." -
- - 041      :validate [#(and (.exists (io/file %)) -
- - 042                       (.isDirectory (io/file %)) -
- - 043                       (.canRead (io/file %)) -
- - 044                       (.canWrite (io/file %))) -
- - 045                 "File path must exist and must be a directory."]] -
- - 046     ["-h" "--help"] -
- - 047     ["-p PROMPT" "--prompt PROMPT" "Set the REPL prompt to PROMPT" -
- - 048      :default "Sprecan::"] -
- - 049     ["-r SYSOUTFILE" "--read SYSOUTFILE" "Read Lisp system from file SYSOUTFILE" -
- - 050      :default default-sysout -
- - 051      :validate [#(and -
- - 052                   (.exists (io/file %)) -
- - 053                   (.canRead (io/file %))) -
- - 054                 "Could not find sysout file"]] + 011  (def cli-options
- 055     ["-s" "--strict" "Strictly interpret the Lisp 1.5 language, without extensions."] -
- - 056     ["-t" "--time" "Time evaluations."]]) -
- - 057   -
- - 058  (defn- re  -
- - 059    "Like REPL, but it isn't a loop and doesn't print." -
- - 060    [input] -
- - 061    (EVAL (READ input) NIL 0)) -
- - 062   -
- - 063  (defn repl -
- - 064    "Read/eval/print loop." -
- - 065    [prompt] -
- - 066    (loop [] -
- - 067      (print prompt) -
- - 068      (flush) -
- - 069      (try -
- - 070        (if-let [input (trim (read-from-console))] -
- - 071          (if (= input stop-word) -
- - 072            (throw (ex-info "\nFærwell!" {:cause :quit})) -
- - 073            (println  -
- - 074             (str ">  "  + 012    [["-h" "--help"]
- 075                  (print-str (if (:time *options*) + 013     ["-p PROMPT" "--prompt PROMPT" "Set the REPL prompt to PROMPT"
- - 076                               (time (re input)) + + 014      :default "Sprecan::"] +
+ + 015     ["-r INITFILE" "--read INITFILE" "Read Lisp functions from the file INITFILE" +
+ + 016      :validate [#(and +
+ + 017                    (.exists (io/file %)) +
+ + 018                    (.canRead (io/file %))) +
+ + 019                 "Could not find initfile"]] +
+ + 020     ["-s" "--strict" "Strictly interpret the Lisp 1.5 language, without extensions."] +
+ + 021     ["-t" "--trace" "Trace Lisp evaluation."]]) +
+ + 022   +
+ + 023  (defn repl +
+ + 024    "Read/eval/print loop." +
+ + 025    [prompt] +
+ + 026    (loop []
- 077                               (re input))))))  + 027      (print prompt) +
+ + 028      (flush) +
+ + 029      (try +
+ + 030        (let [input (read-line)] +
+ + 031          (cond +
+ + 032            (= input "quit") (throw (ex-info "\nFærwell!" {:cause :quit})) +
+ + 033            input (println (str ">  " (print-str (EVAL (READ input) @oblist))))
- 078          (println)) + 034            :else (println)))
- 079        (catch + 035        (catch
- 080         Exception + 036          Exception
- 081         e + 037          e
- 082          (let [data (ex-data e)] + 038          (let [data (ex-data e)]
- 083            (println (.getMessage e)) -
- - 084            (when + 039            (println (.getMessage e))
- 085             data + 040            (if
- - 086              (case (:cause data) + + 041              data +
+ + 042              (case (:cause data)
- 087                :parse-failure (println (:failure data)) + 043                :parse-failure (println (:failure data))
- 088                :strict nil ;; the message, which has already been printed, is enough. + 044                :strict nil ;; the message, which has already been printed, is enough.
- 089                :quit (throw e) + 045                :quit (throw e)
- 090                ;; default + 046                ;; default
- 091                (pprint data)))))) + 047                (pprint data))))))
- 092      (recur))) + 048      (recur)))
- 093   + 049  
- 094  (defn -main + 050  (defn -main
- 095    "Parse options, print the banner, read the init file if any, and enter the + 051    "Parse options, print the banner, read the init file if any, and enter the
- 096    read/eval/print loop." + 052    read/eval/print loop."
- 097    [& opts] + 053    [& opts]
- 098    (let [args (parse-opts opts cli-options)] + 054    (let [args (parse-opts opts cli-options)]
- 099      (println -
- - 100       (str -
- - 101        "\nHider wilcuman. Béowulf is mín nama.\n" -
- - 102        (when -
- - 103         (System/getProperty "beowulf.version") -
- - 104          (str "Síðe " (System/getProperty "beowulf.version") "\n")) -
- - 105        (when -
- - 106         (:help (:options args)) -
- - 107          (:summary args)) -
- - 108        (when (:errors args) -
- - 109          (apply str (interpose "; " (:errors args)))) -
- - 110        "\nSprecan '" stop-word "' tó laéfan\n")) -
- - 111       -
- - 112      (binding [*options* (:options args)] -
- - 113        ;; (pprint *options*) -
- - 114        (when (:read *options*) -
- - 115          (try (SYSIN (:read *options*)) -
- - 116               (catch Throwable any -
- - 117                 (println any)))) -
- - 118        (try -
- - 119          (repl (str (:prompt (:options args)) " ")) -
- - 120          (catch -
- - 121           Exception -
- - 122           e + 055      (println
- 123            (let [data (ex-data e)] + 056        (str +
+ + 057          "\nHider wilcuman. Béowulf is mín nama.\n"
- 124              (if + 058          (if
- - 125               data + + 059            (System/getProperty "beowulf.version")
- 126                (case (:cause data) + 060            (str "Síðe " (System/getProperty "beowulf.version") "\n")) +
+ + 061          (if +
+ + 062            (:help (:options args)) +
+ + 063            (:summary args)) +
+ + 064          (if (:errors args) +
+ + 065            (apply str (interpose "; " (:errors args))))
- 127                  :quit nil + 066          "\nSprecan 'quit' tó laéfan\n")) +
+ + 067      (binding [*options* (:options args)] +
+ + 068        (try +
+ + 069          (repl (str (:prompt (:options args)) " "))
- 128                  ;; default + 070          (catch
- - 129                  (do + + 071            Exception
- - 130                    (println "STÆFLEAHTER: " (.getMessage e)) + + 072            e +
+ + 073            (let [data (ex-data e)] +
+ + 074              (if +
+ + 075                data +
+ + 076                (case (:cause data) +
+ + 077                  :quit nil +
+ + 078                  ;; default
- 131                    (pprint data))) + 079                  (pprint data))
- 132                (println e)))))))) + 080                (println e))))))))
diff --git a/docs/cloverage/beowulf/host.clj.html b/docs/cloverage/beowulf/host.clj.html index 5a4bbed..3acdcf2 100644 --- a/docs/cloverage/beowulf/host.clj.html +++ b/docs/cloverage/beowulf/host.clj.html @@ -14,1708 +14,10 @@ 003     be) implemented in Lisp 1.5, which therefore need to be implemented in the

- 004     host language, in this case Clojure." -
- - 005    (:require [beowulf.cons-cell :refer [F make-beowulf-list make-cons-cell -
- - 006                                         pretty-print T]] ;; note hyphen - this is Clojure... -
- - 007              [beowulf.gendoc :refer [open-doc]] -
- - 008              [beowulf.oblist :refer [*options* NIL oblist]] -
- - 009              [clojure.set :refer [union]] -
- - 010              [clojure.string :refer [upper-case]]) -
- - 011    (:import [beowulf.cons_cell ConsCell] ;; note underscore - same namespace, but Java. -
- - 012             )) -
- - 013   -
- - 014  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 015  ;;; -
- - 016  ;;; Copyright (C) 2022-2023 Simon Brooke -
- - 017  ;;; -
- - 018  ;;; This program is free software; you can redistribute it and/or -
- - 019  ;;; modify it under the terms of the GNU General Public License -
- - 020  ;;; as published by the Free Software Foundation; either version 2 -
- - 021  ;;; of the License, or (at your option) any later version. -
- - 022  ;;;  -
- - 023  ;;; This program is distributed in the hope that it will be useful, -
- - 024  ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -
- - 025  ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -
- - 026  ;;; GNU General Public License for more details. -
- - 027  ;;;  -
- - 028  ;;; You should have received a copy of the GNU General Public License -
- - 029  ;;; along with this program; if not, write to the Free Software -
- - 030  ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. -
- - 031  ;;; -
- - 032  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 033   -
- - 034  ;; these are CANDIDATES to be host-implemented. only a subset of them MUST be. -
- - 035  ;; those which can be implemented in Lisp should be, since that aids -
- - 036  ;; portability. -
- - 037   -
- - 038   -
- - 039  (defn lax? -
- - 040    "Are we in lax mode? If so. return true; is not, throw an exception with  -
- - 041     this `symbol`." -
- - 042    [symbol] -
- - 043    (when (:strict *options*) -
- - 044      (throw (ex-info (format "%s ne āfand innan Lisp 1.5" symbol) -
- - 045                      {:type :strict -
- - 046                       :phase :host -
- - 047                       :function symbol}))) -
- - 048    true) -
- - 049   -
- - 050  ;;;; Basic operations on cons cells ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 051   -
- - 052  (defn CONS -
- - 053    "Construct a new instance of cons cell with this `car` and `cdr`." -
- - 054    [car cdr] -
- - 055    (beowulf.cons_cell.ConsCell. car cdr (gensym "c"))) -
- - 056   -
- - 057  (defn CAR -
- - 058    "Return the item indicated by the first pointer of a pair. NIL is treated -
- - 059    specially: the CAR of NIL is NIL." -
- - 060    [x] -
- - 061    (cond -
- - 062      (= x NIL) NIL -
- - 063      (instance? ConsCell x) (or (.getCar x) NIL) -
- - 064      :else  (throw (ex-info -
- - 065                     (str "Ne can tace CAR of `" x "` (" (.getName (.getClass x)) ")") -
- - 066                     {:phase :host -
- - 067                      :function 'CAR -
- - 068                      :args (list x) -
- - 069                      :type :beowulf})))) -
- - 070   -
- - 071  (defn CDR -
- - 072    "Return the item indicated by the second pointer of a pair. NIL is treated -
- - 073    specially: the CDR of NIL is NIL." -
- - 074    [x] -
- - 075    (cond -
- - 076      (= x NIL) NIL -
- - 077      (instance? ConsCell x) (or (.getCdr x) NIL) -
- - 078      :else  (throw (ex-info -
- - 079                     (str "Ne can tace CDR of `" x "` (" (.getName (.getClass x)) ")") -
- - 080                     {:phase :host -
- - 081                      :function 'CDR -
- - 082                      :args (list x) -
- - 083                      :type :beowulf})))) -
- - 084   -
- - 085   -
- - 086  (defn uaf -
- - 087    "Universal access function; `l` is expected to be an arbitrary LISP list, `path` -
- - 088    a (clojure) list of the characters `a` and `d`. Intended to make declaring -
- - 089    all those fiddly `#'c[ad]+r'` functions a bit easier" -
- - 090    [l path] -
- - 091    (cond -
- - 092      (= l NIL) NIL -
- - 093      (empty? path) l -
- - 094      :else -
- - 095      (try -
- - 096        (case (last path) -
- - 097          \a (uaf (.first l) (butlast path)) -
- - 098          \d (uaf (.getCdr l) (butlast path)) -
- - 099          (throw (ex-info (str "uaf: unexpected letter in path (only `a` and `d` permitted): " (last path)) -
- - 100                          {:cause  :uaf -
- - 101                           :detail :unexpected-letter -
- - 102                           :expr   (last path)}))) -
- - 103        (catch ClassCastException e -
- - 104          (throw (ex-info -
- - 105                  (str "uaf: Not a LISP list? " (type l)) -
- - 106                  {:cause  :uaf -
- - 107                   :detail :not-a-lisp-list -
- - 108                   :expr   l} -
- - 109                  e)))))) -
- - 110   -
- - 111  (defmacro CAAR [x] `(uaf ~x '(\a \a))) -
- - 112  (defmacro CADR [x] `(uaf ~x '(\a \d))) -
- - 113  (defmacro CDDR [x] `(uaf ~x '(\d \d))) -
- - 114  (defmacro CDAR [x] `(uaf ~x '(\d \a))) -
- - 115   -
- - 116  (defmacro CAAAR [x] `(uaf ~x '(\a \a \a))) -
- - 117  (defmacro CAADR [x] `(uaf ~x '(\a \a \d))) -
- - 118  (defmacro CADAR [x] `(uaf ~x '(\a \d \a))) -
- - 119  (defmacro CADDR [x] `(uaf ~x '(\a \d \d))) -
- - 120  (defmacro CDDAR [x] `(uaf ~x '(\d \d \a))) -
- - 121  (defmacro CDDDR [x] `(uaf ~x '(\d \d \d))) -
- - 122  (defmacro CDAAR [x] `(uaf ~x '(\d \a \a))) -
- - 123  (defmacro CDADR [x] `(uaf ~x '(\d \a \d))) -
- - 124   -
- - 125  (defmacro CAAAAR [x] `(uaf ~x '(\a \a \a \a))) -
- - 126  (defmacro CAADAR [x] `(uaf ~x '(\a \a \d \a))) -
- - 127  (defmacro CADAAR [x] `(uaf ~x '(\a \d \a \a))) -
- - 128  (defmacro CADDAR [x] `(uaf ~x '(\a \d \d \a))) -
- - 129  (defmacro CDDAAR [x] `(uaf ~x '(\d \d \a \a))) -
- - 130  (defmacro CDDDAR [x] `(uaf ~x '(\d \d \d \a))) -
- - 131  (defmacro CDAAAR [x] `(uaf ~x '(\d \a \a \a))) -
- - 132  (defmacro CDADAR [x] `(uaf ~x '(\d \a \d \a))) -
- - 133  (defmacro CAAADR [x] `(uaf ~x '(\a \a \a \d))) -
- - 134  (defmacro CAADDR [x] `(uaf ~x '(\a \a \d \d))) -
- - 135  (defmacro CADADR [x] `(uaf ~x '(\a \d \a \d))) -
- - 136  (defmacro CADDDR [x] `(uaf ~x '(\a \d \d \d))) -
- - 137  (defmacro CDDADR [x] `(uaf ~x '(\d \d \a \d))) -
- - 138  (defmacro CDDDDR [x] `(uaf ~x '(\d \d \d \d))) -
- - 139  (defmacro CDAADR [x] `(uaf ~x '(\d \a \a \d))) -
- - 140  (defmacro CDADDR [x] `(uaf ~x '(\d \a \d \d))) -
- - 141   -
- - 142  (defn RPLACA -
- - 143    "Replace the CAR pointer of this `cell` with this `value`. Dangerous, should -
- - 144    really not exist, but does in Lisp 1.5 (and was important for some -
- - 145    performance hacks in early Lisps)" -
- - 146    [^ConsCell cell value] -
- - 147    (if -
- - 148     (instance? ConsCell cell) -
- - 149      (if -
- - 150       (or -
- - 151        (instance? ConsCell value) -
- - 152        (number? value) -
- - 153        (symbol? value) -
- - 154        (= value NIL)) -
- - 155        (try -
- - 156          (.rplaca cell value) -
- - 157          cell -
- - 158          (catch Throwable any -
- - 159            (throw (ex-info -
- - 160                    (str (.getMessage any) " in RPLACA: `") -
- - 161                    {:cause :upstream-error -
- - 162                     :phase :host -
- - 163                     :function :rplaca -
- - 164                     :args (list cell value) -
- - 165                     :type :beowulf} -
- - 166                    any)))) -
- - 167        (throw (ex-info -
- - 168                (str "Un-ġefōg þing in RPLACA: `" value "` (" (type value) ")") -
- - 169                {:cause :bad-value -
- - 170                 :phase :host -
- - 171                 :function :rplaca -
- - 172                 :args (list cell value) -
- - 173                 :type :beowulf}))) -
- - 174      (throw (ex-info -
- - 175              (str "Uncynlic miercels in RPLACA: `" cell "` (" (type cell) ")") -
- - 176              {:cause :bad-cell -
- - 177               :phase :host -
- - 178               :function :rplaca -
- - 179               :args (list cell value) -
- - 180               :type :beowulf})))) -
- - 181   -
- - 182  (defn RPLACD -
- - 183    "Replace the CDR pointer of this `cell` with this `value`. Dangerous, should -
- - 184    really not exist, but does in Lisp 1.5 (and was important for some -
- - 185    performance hacks in early Lisps)" -
- - 186    [^ConsCell cell value] -
- - 187    (if -
- - 188     (instance? ConsCell cell) -
- - 189      (if -
- - 190       (or -
- - 191        (instance? ConsCell value) -
- - 192        (number? value) -
- - 193        (symbol? value) -
- - 194        (= value NIL)) -
- - 195        (try -
- - 196          (.rplacd cell value) -
- - 197          cell -
- - 198          (catch Throwable any -
- - 199            (throw (ex-info -
- - 200                    (str (.getMessage any) " in RPLACD: `") -
- - 201                    {:cause :upstream-error -
- - 202                     :phase :host -
- - 203                     :function :rplacd -
- - 204                     :args (list cell value) -
- - 205                     :type :beowulf} -
- - 206                    any)))) -
- - 207        (throw (ex-info -
- - 208                (str "Un-ġefōg þing in RPLACD: `" value "` (" (type value) ")") -
- - 209                {:cause :bad-value -
- - 210                 :phase :host -
- - 211                 :function :rplacd -
- - 212                 :args (list cell value) -
- - 213                 :type :beowulf}))) -
- - 214      (throw (ex-info -
- - 215              (str "Uncynlic miercels in RPLACD: `" cell "` (" (type cell) ")") -
- - 216              {:cause :bad-cell -
- - 217               :phase :host -
- - 218               :detail :rplacd -
- - 219               :args (list cell value) -
- - 220               :type :beowulf}))));; PLUS -
- - 221   -
- - 222  (defn LIST -
- - 223    [& args] -
- - 224    (make-beowulf-list args)) -
- - 225   -
- - 226  ;;;; Basic predicates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 227   -
- - 228  (defmacro NULL -
- - 229    "Returns `T` if and only if the argument `x` is bound to `NIL`; else `F`." -
- - 230    [x] -
- - 231    `(if (= ~x NIL) T F)) -
- - 232   -
- - 233  (defmacro NILP -
- - 234    "Not part of LISP 1.5: `T` if `o` is `NIL`, else `NIL`." -
- - 235    [x] -
- - 236    `(if (= ~x NIL) T NIL)) -
- - 237   -
- - 238  (defn ATOM -
- - 239    "Returns `T` if and only if the argument `x` is bound to an atom; else `F`. -
- - 240    It is not clear to me from the documentation whether `(ATOM 7)` should return -
- - 241    `T` or `F`. I'm going to assume `T`." -
- - 242    [x] -
- - 243    (if (or (symbol? x) (number? x)) T F)) -
- - 244   -
- - 245  (defmacro ATOM? -
- - 246    "The convention of returning `F` from predicates, rather than `NIL`, is going -
- - 247    to tie me in knots. This is a variant of `ATOM` which returns `NIL` -
- - 248    on failure." -
- - 249    [x] -
- - 250    `(if (or (symbol? ~x) (number? ~x)) T NIL)) -
- - 251   -
- - 252  (defn EQ -
- - 253    "Returns `T` if and only if both `x` and `y` are bound to the same atom, -
- - 254    else `NIL`." -
- - 255    [x y] -
- - 256    (cond (and (instance? ConsCell x) -
- - 257               (.equals x y)) T -
- - 258          (and (= (ATOM x) T) (= x y)) T -
- - 259          :else NIL)) -
- - 260   -
- - 261  (defn EQUAL -
- - 262    "This is a predicate that is true if its two arguments are identical -
- - 263    S-expressions, and false if they are different. (The elementary predicate -
- - 264    `EQ` is defined only for atomic arguments.) The definition of `EQUAL` is -
- - 265    an example of a conditional expression inside a conditional expression. -
- - 266   -
- - 267    NOTE: returns `F` on failure, not `NIL`" -
- - 268    [x y] -
- - 269    (cond -
- - 270      (= (ATOM x) T) (if (= x y) T F) -
- - 271      (= (EQUAL (CAR x) (CAR y)) T) (EQUAL (CDR x) (CDR y)) -
- - 272      :else F)) -
- - 273   -
- - 274  (defn AND -
- - 275    "`T` if and only if none of my `args` evaluate to either `F` or `NIL`, -
- - 276     else `F`. -
- - 277      -
- - 278     In `beowulf.host` principally because I don't yet feel confident to define -
- - 279     varargs functions in Lisp." -
- - 280    [& args] -
- - 281    ;; (println "AND: " args " type: " (type args) " seq? " (seq? args)) -
- - 282    ;; (println "  filtered: " (seq (filter #{F NIL} args))) -
- - 283    (cond (= NIL args) T -
- - 284          (seq? args) (if (seq (filter #{F NIL} args)) F T) -
- - 285          :else T)) -
- - 286   -
- - 287   -
- - 288  (defn OR -
- - 289    "`T` if and only if at least one of my `args` evaluates to something other -
- - 290    than either `F` or `NIL`, else `F`. -
- - 291      -
- - 292     In `beowulf.host` principally because I don't yet feel confident to define -
- - 293     varargs functions in Lisp." -
- - 294    [& args] -
- - 295    ;; (println "OR: " args " type: " (type args) " seq? " (seq? args)) -
- - 296    ;; (println "  filtered: " (seq (remove #{F NIL} args))) -
- - 297    (cond (= NIL args) F -
- - 298          (seq? args) (if (seq (remove #{F NIL} args)) T F) -
- - 299          :else F)) -
- - 300   -
- - 301   -
- - 302  ;;;; Operations on lists ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 303  ;; -
- - 304  ;; TODO: These are candidates for moving to Lisp urgently! -
- - 305   -
- - 306  (defn ASSOC -
- - 307    "If a is an association list such as the one formed by PAIRLIS in the above -
- - 308    example, then assoc will produce the first pair whose first term is x. Thus -
- - 309    it is a table searching function. -
- - 310   -
- - 311    All args are assumed to be `beowulf.cons-cell/ConsCell` objects. -
- - 312    See page 12 of the Lisp 1.5 Programmers Manual. -
- - 313      -
- - 314     **NOTE THAT** this function is overridden by an implementation in Lisp, -
- - 315     but is currently still present for bootstrapping." -
- - 316    [x a] -
- - 317    (cond -
- - 318      (= NIL a) NIL ;; this clause is not present in the original but is added for -
- - 319      ;; robustness. -
- - 320      (= (EQUAL (CAAR a) x) T) (CAR a) -
- - 321      :else -
- - 322      (ASSOC x (CDR a)))) -
- - 323   -
- - 324  (defn PAIRLIS -
- - 325    "This function gives the list of pairs of corresponding elements of the -
- - 326    lists `x` and `y`, and APPENDs this to the list `a`. The resultant list -
- - 327    of pairs, which is like a table with two columns, is called an -
- - 328    association list. -
- - 329   -
- - 330    Eessentially, it builds the environment on the stack, implementing shallow -
- - 331    binding. -
- - 332   -
- - 333    All args are assumed to be `beowulf.cons-cell/ConsCell` objects. -
- - 334    See page 12 of the Lisp 1.5 Programmers Manual. -
- - 335      -
- - 336     **NOTE THAT** this function is overridden by an implementation in Lisp, -
- - 337     but is currently still present for bootstrapping." -
- - 338    [x y a] -
- - 339    (cond -
- - 340      ;; the original tests only x; testing y as well will be a little more -
- - 341      ;; robust if `x` and `y` are not the same length. -
- - 342      (or (= NIL x) (= NIL y)) a -
- - 343      :else (make-cons-cell -
- - 344             (make-cons-cell (CAR x) (CAR y)) -
- - 345             (PAIRLIS (CDR x) (CDR y) a)))) + 004     host language, in this case Clojure.")
- 346   -
- - 347  ;;;; Arithmetic ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 348  ;; -
- - 349  ;; TODO: When in strict mode, should we limit arithmetic precision to that -
- - 350  ;; supported by Lisp 1.5? -
- - 351   -
- - 352  (defn PLUS -
- - 353    [& args] -
- - 354    (let [s (apply + args)] -
- - 355      (if (integer? s) s (float s)))) -
- - 356   -
- - 357  (defn TIMES -
- - 358    [& args] -
- - 359    (let [p (apply * args)] -
- - 360      (if (integer? p) p (float p)))) -
- - 361   -
- - 362  (defn DIFFERENCE -
- - 363    [x y] -
- - 364    (let [d (- x y)] -
- - 365      (if (integer? d) d (float d)))) -
- - 366   -
- - 367  (defn QUOTIENT -
- - 368    "I'm not certain from the documentation whether Lisp 1.5 `QUOTIENT` returned -
- - 369    the integer part of the quotient, or a realnum representing the whole -
- - 370    quotient. I am for now implementing the latter." -
- - 371    [x y] -
- - 372    (let [q (/ x y)] -
- - 373      (if (integer? q) q (float q)))) -
- - 374   -
- - 375  (defn REMAINDER -
- - 376    [x y] -
- - 377    (rem x y)) -
- - 378   -
- - 379  (defn ADD1 -
- - 380    [x] -
- - 381    (inc x)) -
- - 382   -
- - 383  (defn SUB1 -
- - 384    [x] -
- - 385    (dec x)) -
- - 386   -
- - 387  (defn FIXP -
- - 388    [x] -
- - 389    (if (integer? x) T F)) -
- - 390   -
- - 391  (defn NUMBERP -
- - 392    [x] -
- - 393    (if (number? x) T F)) -
- - 394   -
- - 395  (defn LESSP -
- - 396    [x y] -
- - 397    (if (< x y) T F)) -
- - 398   -
- - 399  (defn GREATERP -
- - 400    [x y] -
- - 401    (if (> x y) T F)) -
- - 402   -
- - 403  ;;;; Miscellaneous ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 404   -
- - 405  (defn GENSYM -
- - 406    "Generate a unique symbol." -
- - 407    [] -
- - 408    (symbol (upper-case (str (gensym "SYM"))))) -
- - 409   -
- - 410  (defn ERROR -
- - 411    "Throw an error" -
- - 412    [& args] -
- - 413    (throw (ex-info "LISP STÆFLEAHTER" {:args args -
- - 414                                        :phase :eval -
- - 415                                        :function 'ERROR -
- - 416                                        :type :lisp -
- - 417                                        :code (or (first args) 'A1)}))) -
- - 418   -
- - 419  ;;;; Assignment and the object list ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 420   -
- - 421  (defn OBLIST -
- - 422    "Return a list of the symbols currently bound on the object list. -
- - 423      -
- - 424     **NOTE THAT** in the Lisp 1.5 manual, footnote at the bottom of page 69, it implies  -
- - 425     that an argument can be passed but I'm not sure of the semantics of -
- - 426     this." -
- - 427    [] -
- - 428    (if (instance? ConsCell @oblist) -
- - 429      (make-beowulf-list (map CAR @oblist)) -
- - 430      NIL)) -
- - 431   -
- - 432  (def magic-marker -
- - 433    "The unexplained magic number which marks the start of a property list." -
- - 434    (Integer/parseInt "77777" 8)) -
- - 435   -
- - 436  (defn PUT -
- - 437    "Put this `value` as the value of the property indicated by this `indicator`  -
- - 438     of this `symbol`. Return `value` on success. -
- - 439      -
- - 440     NOTE THAT there is no `PUT` defined in the manual, but it would have been  -
- - 441     easy to have defined it so I don't think this fully counts as an extension." -
- - 442    [symbol indicator value] -
- - 443    (if-let [binding (ASSOC symbol @oblist)] -
- - 444      (if-let [prop (ASSOC indicator (CDDR binding))] -
- - 445        (RPLACD prop value) -
- - 446        (RPLACD binding -
- - 447                (make-cons-cell -
- - 448                 magic-marker -
- - 449                 (make-cons-cell -
- - 450                  indicator -
- - 451                  (make-cons-cell value (CDDR binding)))))) -
- - 452      (swap! -
- - 453       oblist -
- - 454       (fn [ob s p v] -
- - 455         (make-cons-cell -
- - 456          (make-beowulf-list (list s magic-marker p v)) -
- - 457          ob)) -
- - 458       symbol indicator value))) -
- - 459   -
- - 460  (defn GET -
- - 461    "From the manual: -
- - 462      -
- - 463     '`get` is somewhat like `prop`; however its value is car of the rest of -
- - 464     the list if the `indicator` is found, and NIL otherwise.' -
- - 465      -
- - 466     It's clear that `GET` is expected to be defined in terms of `PROP`, but -
- - 467     we can't implement `PROP` here because we lack `EVAL`; and we can't have -
- - 468     `EVAL` here because both it and `APPLY` depends on `GET`. -
- - 469      -
- - 470     OK, It's worse than that: the statement of the definition of `GET` (and  -
- - 471     of) `PROP` on page 59 says that the first argument to each must be a list; -
- - 472     But the in the definition of `ASSOC` on page 70, when `GET` is called its -
- - 473     first argument is always an atom. Since it's `ASSOC` and `EVAL` which I  -
- - 474     need to make work, I'm going to assume that page 59 is wrong." -
- - 475    [symbol indicator] -
- - 476    (let [binding (ASSOC symbol @oblist) -
- - 477          val (cond -
- - 478                (= binding NIL) NIL -
- - 479                (= magic-marker -
- - 480                   (CADR binding)) (loop [b binding] -
- - 481                                    ;;  (println "GET loop, seeking " indicator ":") -
- - 482                                    ;;  (pretty-print b) -
- - 483                                     (if (instance? ConsCell b) -
- - 484                                       (if (= (CAR b) indicator) -
- - 485                                         (CADR b) ;; <- this is what we should actually be returning -
- - 486                                         (recur (CDR b))) -
- - 487                                       NIL)) -
- - 488                :else (throw -
- - 489                       (ex-info "Misformatted property list (missing magic marker)" -
- - 490                                {:phase :host -
- - 491                                 :function :get -
- - 492                                 :args (list symbol indicator) -
- - 493                                 :type :beowulf})))] -
- - 494      ;; (println "<< GET returning: " val) -
- - 495      val)) -
- - 496   -
- - 497  (defn DEFLIST -
- - 498    "For each pair in this association list `a-list`, set the property with this -
- - 499     `indicator` of the symbol which is the first element of the pair to the  -
- - 500     value which is the second element of the pair. See page 58 of the manual." -
- - 501    [a-list indicator] -
- - 502    (map -
- - 503     #(PUT (CAR %) indicator (CDR %)) -
- - 504     a-list)) -
- - 505   -
- - 506  (defn DEFINE -
- - 507    "Bootstrap-only version of `DEFINE` which, post boostrap, can be overwritten  -
- - 508    in LISP.  -
- - 509   -
- - 510    The single argument to `DEFINE` should be an association list of symbols to -
- - 511     lambda functions. See page 58 of the manual." -
- - 512    [a-list] -
- - 513    (DEFLIST a-list 'EXPR)) -
- - 514   -
- - 515  (defn SET -
- - 516    "Implementation of SET in Clojure. Add to the `oblist` a binding of the -
- - 517     value of `var` to the value of `val`. NOTE WELL: this is not SETQ!" -
- - 518    [symbol val] -
- - 519    (PUT symbol 'APVAL val)) -
- - 520   -
- - 521  ;;;; TRACE and friends ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 522   -
- - 523  (def traced-symbols -
- - 524    "Symbols currently being traced." -
- - 525    (atom #{})) -
- - 526   -
- - 527  (defn traced? -
- - 528    "Return `true` iff `s` is a symbol currently being traced, else `nil`." -
- - 529    [s] -
- - 530    (try (contains? @traced-symbols s) -
- - 531         (catch Throwable _ nil))) -
- - 532   -
- - 533  (defn TRACE -
- - 534    "Add this `s` to the set of symbols currently being traced. If `s` -
- - 535     is not a symbol or sequence of symbols, does nothing." -
- - 536    [s] -
- - 537    (swap! traced-symbols -
- - 538           #(cond -
- - 539              (symbol? s) (conj % s) -
- - 540              (and (seq? s) (every? symbol? s)) (union % (set s)) -
- - 541              :else %))) -
- - 542   -
- - 543  (defn UNTRACE -
- - 544    "Remove this `s` from the set of symbols currently being traced. If `s` -
- - 545     is not a symbol or sequence of symbols, does nothing." -
- - 546    [s] -
- - 547    (cond -
- - 548      (symbol? s) (swap! traced-symbols #(set (remove (fn [x] (= s x)) %))) -
- - 549      (and (seq? s) (every? symbol? s)) (map UNTRACE s)) -
- - 550    @traced-symbols) -
- - 551   -
- - 552  ;;;; Extensions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 553   -
- - 554  (defn DOC -
- - 555    "Open the page for this `symbol` in the Lisp 1.5 manual, if known, in the  -
- - 556      default web browser. -
- - 557      -
- - 558     **NOTE THAT** this is an extension function, not available in strct mode." -
- - 559    [symbol] -
- - 560    (when (lax? 'DOC) -
- - 561      (open-doc symbol))) -
- - 562   -
- - 563  (defn CONSP -
- - 564    "Return `T` if object `o` is a cons cell, else `F`. -
- - 565      -
- - 566     **NOTE THAT** this is an extension function, not available in strct mode.  -
- - 567     I believe that Lisp 1.5 did not have any mechanism for testing whether an -
- - 568     argument was, or was not, a cons cell." -
- - 569    [o] -
- - 570    (when (lax? 'CONSP) -
- - 571      (if (instance? ConsCell o) 'T 'F))) + 005  
diff --git a/docs/cloverage/beowulf/interop.clj.html b/docs/cloverage/beowulf/interop.clj.html deleted file mode 100644 index 0dd6c5c..0000000 --- a/docs/cloverage/beowulf/interop.clj.html +++ /dev/null @@ -1,395 +0,0 @@ - - - - beowulf/interop.clj - - - - 001  (ns beowulf.interop -
- - 002    (:require [beowulf.cons-cell :refer [make-beowulf-list]] -
- - 003              [beowulf.host :refer [CAR CDR]] -
- - 004              [beowulf.oblist :refer [*options* NIL]] -
- - 005              [clojure.string :as s :refer [last-index-of lower-case split -
- - 006                                            upper-case]])) -
- - 007   -
- - 008  ;;;; INTEROP feature ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 009   -
- - 010  (defn listify-qualified-name -
- - 011    "We need to be able to print something we can link to the particular Clojure -
- - 012     function `subr` in a form in which Lisp 1.5 is able to read it back in and -
- - 013     relink it. -
- - 014      -
- - 015     This assumes `subr` is either  -
- - 016     1. a string in the format `#'beowulf.io/SYSIN` or `beowulf.io/SYSIN`; or -
- - 017     2. something which, when coerced to a string with `str`, will have such -
- - 018        a format." -
- - 019    [subr] -
- - 020    (make-beowulf-list -
- - 021     (map -
- - 022      #(symbol (upper-case %)) -
- - 023      (remove empty? (split (str subr) #"[#'./]"))))) -
- - 024   -
- - 025   -
- - 026  (defn interpret-qualified-name -
- - 027    "For interoperation with Clojure, it will often be necessary to pass -
- - 028    qualified names that are not representable in Lisp 1.5. This function -
- - 029    takes a sequence in the form `(PART PART PART... NAME)` and returns -
- - 030    a symbol in the form `part.part.part/NAME`. This symbol will then be -
- - 031    tried in both that form and lower-cased. Names with hyphens or -
- - 032    underscores cannot be represented with this scheme." -
- - 033    ([l] -
- - 034     (symbol -
- - 035      (let [n (s/join "."  -
- - 036                      (concat (map #(lower-case (str %)) (butlast l))  -
- - 037                              (list (last l)))) -
- - 038            s (last-index-of n ".")] -
- - 039        (if s -
- - 040          (str (subs n 0 s) "/" (subs n (inc s))) -
- - 041          n))))) -
- - 042   -
- - 043  (defn to-beowulf -
- - 044    "Return a beowulf-native representation of the Clojure object `o`. -
- - 045    Numbers and symbols are unaffected. Collections have to be converted; -
- - 046    strings must be converted to symbols." -
- - 047    [o] -
- - 048    (cond -
- - 049      (coll? o) (make-beowulf-list o) -
- - 050      (string? o) (symbol (s/upper-case o)) -
- - 051      :else o)) -
- - 052   -
- - 053  (defn to-clojure -
- - 054    "If l is a `beowulf.cons_cell.ConsCell`, return a Clojure list having the  -
- - 055    same members in the same order." -
- - 056    [l] -
- - 057    (cond -
- - 058      (not (instance? beowulf.cons_cell.ConsCell l)) -
- - 059      l -
- - 060      (= (CDR l) NIL) -
- - 061      (list (to-clojure (CAR l))) -
- - 062      :else -
- - 063      (conj (to-clojure (CDR l)) (to-clojure (CAR l))))) -
- - 064   -
- - 065  (defn INTEROP -
- - 066    "Clojure (or other host environment) interoperation API. `fn-symbol` is expected -
- - 067    to be either -
- - 068   -
- - 069    1. a symbol bound in the host environment to a function; or -
- - 070    2. a sequence (list) of symbols forming a qualified path name bound to a -
- - 071       function. -
- - 072   -
- - 073    Lower case characters cannot normally be represented in Lisp 1.5, so both the -
- - 074    upper case and lower case variants of `fn-symbol` will be tried. If the -
- - 075    function you're looking for has a mixed case name, that is not currently -
- - 076    accessible. -
- - 077   -
- - 078    `args` is expected to be a Lisp 1.5 list of arguments to be passed to that -
- - 079    function. Return value must be something acceptable to Lisp 1.5, so either -
- - 080    a symbol, a number, or a Lisp 1.5 list. -
- - 081   -
- - 082    If `fn-symbol` is not found (even when cast to lower case), or is not a function, -
- - 083    or the value returned cannot be represented in Lisp 1.5, an exception is thrown -
- - 084    with `:cause` bound to `:interop` and `:detail` set to a value representing the -
- - 085    actual problem." -
- - 086    [fn-symbol args] -
- - 087    (if-not (:strict *options*) -
- - 088      (let -
- - 089       [q-name (if -
- - 090                (seq? fn-symbol) -
- - 091                 (interpret-qualified-name fn-symbol) -
- - 092                 fn-symbol) -
- - 093        l-name (symbol (s/lower-case q-name)) -
- - 094        f      (cond -
- - 095                 (try -
- - 096                   (fn? (eval l-name)) -
- - 097                   (catch java.lang.ClassNotFoundException _ nil)) l-name -
- - 098                 (try -
- - 099                   (fn? (eval q-name)) -
- - 100                   (catch java.lang.ClassNotFoundException _ nil)) q-name -
- - 101                 :else (throw -
- - 102                        (ex-info -
- - 103                         (str "INTEROP: ungecnáwen þegnung `" fn-symbol "`") -
- - 104                         {:cause      :interop -
- - 105                          :detail     :not-found -
- - 106                          :name       fn-symbol -
- - 107                          :also-tried l-name}))) -
- - 108        args'  (to-clojure args)] -
- - 109  ;;      (print (str "INTEROP: eahtiende `" (cons f args') "`")) -
- - 110        (flush) -
- - 111        (let [result (eval (conj args' f))] ;; this has the potential to blow up the world -
- - 112  ;;        (println (str "; ágiefende `" result "`")) -
- - 113          (cond -
- - 114            (instance? beowulf.cons_cell.ConsCell result) result -
- - 115            (coll? result) (make-beowulf-list result) -
- - 116            (symbol? result) result -
- - 117            (string? result) (symbol result) -
- - 118            (number? result) result -
- - 119            :else (throw -
- - 120                   (ex-info -
- - 121                    (str "INTEROP: Ne can eahtiende `" result "` to Lisp 1.5.") -
- - 122                    {:cause  :interop -
- - 123                     :detail :not-representable -
- - 124                     :result result}))))) -
- - 125      (throw -
- - 126       (ex-info -
- - 127        (str "INTEROP ne āfand innan Lisp 1.5.") -
- - 128        {:cause  :interop -
- - 129         :detail :strict})))) -
- - diff --git a/docs/cloverage/beowulf/io.clj.html b/docs/cloverage/beowulf/io.clj.html deleted file mode 100644 index 2ef3c37..0000000 --- a/docs/cloverage/beowulf/io.clj.html +++ /dev/null @@ -1,521 +0,0 @@ - - - - beowulf/io.clj - - - - 001  (ns beowulf.io -
- - 002    "Non-standard extensions to Lisp 1.5 to read and write to the filesystem. -
- - 003      -
- - 004     Lisp 1.5 had only `READ`, which read one S-Expression at a time, and  -
- - 005     various forms of `PRIN*` functions, which printed to the line printer.  -
- - 006     There was also `PUNCH`, which wrote to a card punch. It does not seem  -
- - 007     that there was any concept of an interactive terminal. -
- - 008      -
- - 009     See Appendix E, `OVERLORD - THE MONITOR`, and Appendix F, `LISP INPUT -
- - 010     AND OUTPUT`. -
- - 011      -
- - 012     For our purposes, to save the current state of the Lisp system it should -
- - 013     be sufficient to print the current contents of the oblist to file; and to -
- - 014     restore a previous state from file, to overwrite the contents of the  -
- - 015     oblist with data from that file. -
- - 016      -
- - 017     Hence functions SYSOUT and SYSIN, which do just that." -
- - 018    (:require [beowulf.cons-cell :refer [make-beowulf-list make-cons-cell -
- - 019                                         pretty-print]] -
- - 020              [beowulf.host :refer [CADR CAR CDDR CDR]] -
- - 021              [beowulf.interop :refer [interpret-qualified-name -
- - 022                                       listify-qualified-name]] -
- - 023              [beowulf.oblist :refer [*options* NIL oblist]] -
- - 024              [beowulf.read :refer [READ]] -
- - 025              [clojure.java.io :refer [file resource]] -
- - 026              [clojure.string :refer [ends-with?]] -
- - 027              [java-time.api :refer [local-date local-date-time]])) -
- - 028   -
- - 029  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 030  ;;; -
- - 031  ;;; Copyright (C) 2022-2023 Simon Brooke -
- - 032  ;;; -
- - 033  ;;; This program is free software; you can redistribute it and/or -
- - 034  ;;; modify it under the terms of the GNU General Public License -
- - 035  ;;; as published by the Free Software Foundation; either version 2 -
- - 036  ;;; of the License, or (at your option) any later version. -
- - 037  ;;;  -
- - 038  ;;; This program is distributed in the hope that it will be useful, -
- - 039  ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -
- - 040  ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -
- - 041  ;;; GNU General Public License for more details. -
- - 042  ;;;  -
- - 043  ;;; You should have received a copy of the GNU General Public License -
- - 044  ;;; along with this program; if not, write to the Free Software -
- - 045  ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. -
- - 046  ;;; -
- - 047  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 048   -
- - 049  (def ^:constant default-sysout "lisp1.5.lsp") -
- - 050   -
- - 051  (defn- full-path -
- - 052    [fp] -
- - 053    (str -
- - 054     (if (:filepath *options*) -
- - 055       (str (:filepath *options*) (java.io.File/separator)) -
- - 056       "") -
- - 057     (if (and (string? fp) -
- - 058              (> (count fp) 0) -
- - 059              (not= fp "NIL")) -
- - 060       fp -
- - 061       (str "Sysout-" (local-date))) -
- - 062     (if (ends-with? fp ".lsp") -
- - 063       "" -
- - 064       ".lsp"))) -
- - 065   -
- - 066  ;; (find-var (symbol "beowulf.io/SYSIN")) -
- - 067  ;; (@(resolve (symbol "beowulf.host/TIMES")) 2 2) -
- - 068   -
- - 069  (defn safely-wrap-subr -
- - 070    [entry] -
- - 071    (cond (= entry NIL) NIL -
- - 072          (= (CAR entry) 'SUBR) (make-cons-cell -
- - 073                                 (CAR entry) -
- - 074                                 (make-cons-cell -
- - 075                                  (listify-qualified-name (CADR entry)) -
- - 076                                  (CDDR entry))) -
- - 077          :else (make-cons-cell -
- - 078                 (CAR entry) (safely-wrap-subr (CDR entry))))) -
- - 079   -
- - 080  (defn safely-wrap-subrs -
- - 081    [objects] -
- - 082    (make-beowulf-list (map safely-wrap-subr objects))) -
- - 083   -
- - 084  (defn SYSOUT -
- - 085    "Dump the current content of the object list to file. If no `filepath` is -
- - 086     specified, a file name will be constructed of the symbol `Sysout` and  -
- - 087     the current date. File paths will be considered relative to the filepath -
- - 088     set when starting Lisp. -
- - 089      -
- - 090     **NOTE THAT** this is an extension function, not available in strct mode." -
- - 091    ([] -
- - 092     (SYSOUT nil)) -
- - 093    ([filepath] -
- - 094     (spit (full-path (str filepath)) -
- - 095           (with-out-str -
- - 096             (println (apply str (repeat 79 ";"))) -
- - 097             (println (format ";; Beowulf %s Sysout file generated at %s" -
- - 098                              (or (System/getProperty "beowulf.version") "") -
- - 099                              (local-date-time))) -
- - 100             (when (System/getenv "USER") -
- - 101               (println (format ";; generated by %s" (System/getenv "USER")))) -
- - 102             (println (apply str (repeat 79 ";"))) -
- - 103             (println) -
- - 104             (let [output (safely-wrap-subrs @oblist)] -
- - 105               (pretty-print output) -
- - 106               ))))) -
- - 107   -
- - 108  (defn resolve-subr -
- - 109    "If this oblist `entry` references a subroutine, attempt to fix up that -
- - 110     reference." -
- - 111    ([entry] -
- - 112     (or (resolve-subr entry 'SUBR) -
- - 113         (resolve-subr entry 'FSUBR))) -
- - 114    ([entry prop] -
- - 115     (cond (= entry NIL) NIL -
- - 116          (= (CAR entry) prop) (try -
- - 117                                  (make-cons-cell -
- - 118                                   (CAR entry) -
- - 119                                   (make-cons-cell -
- - 120                                    (interpret-qualified-name -
- - 121                                           (CADR entry)) -
- - 122                                    (CDDR entry))) -
- - 123                                  (catch Exception _ -
- - 124                                    (print "Warnung: ne can āfinde " -
- - 125                                           (CADR entry)) -
- - 126                                    (CDDR entry))) -
- - 127          :else (make-cons-cell -
- - 128                 (CAR entry) (resolve-subr (CDR entry)))))) -
- - 129   -
- - 130   -
- - 131  (defn- resolve-subroutines -
- - 132    "Attempt to fix up the references to subroutines (Clojure functions) among -
- - 133     these `objects`, being new content for the object list." -
- - 134    [objects] -
- - 135    (make-beowulf-list -
- - 136     (map -
- - 137      resolve-subr -
- - 138      objects))) -
- - 139   -
- - 140  (defn SYSIN -
- - 141    "Read the contents of the file at this `filename` into the object list.  -
- - 142      -
- - 143     If the file is not a valid Beowulf sysout file, this will probably  -
- - 144     corrupt the system, you have been warned. File paths will be considered  -
- - 145     relative to the filepath set when starting Lisp. -
- - 146   -
- - 147     It is intended that sysout files can be read both from resources within -
- - 148     the jar file, and from the file system. If a named file exists in both the -
- - 149     file system and the resources, the file system will be preferred. -
- - 150      -
- - 151     **NOTE THAT** if the provided `filename` does not end with `.lsp` (which, -
- - 152     if you're writing it from the Lisp REPL, it won't), the extension `.lsp` -
- - 153     will be appended. -
- - 154      -
- - 155     **NOTE THAT** this is an extension function, not available in strct mode." -
- - 156    ([] -
- - 157     (SYSIN (or (:read *options*) (str "resources/" default-sysout)))) -
- - 158    ([filename] -
- - 159     (let [fp (file (full-path (str filename))) -
- - 160           file (when (and (.exists fp) (.canRead fp)) fp) -
- - 161           res (try (resource filename) -
- - 162                    (catch Throwable _ nil)) -
- - 163           content (try (READ (slurp (or file res))) -
- - 164                        (catch Throwable _ -
- - 165                          (throw (ex-info "Ne can ārǣde" -
- - 166                                          {:context "SYSIN" -
- - 167                                           :filename filename -
- - 168                                           :filepath fp}))))] -
- - 169       (swap! oblist -
- - 170              #(when (or % (seq content)) -
- - 171                 (resolve-subroutines content)))))) -
- - diff --git a/docs/cloverage/beowulf/manual.clj.html b/docs/cloverage/beowulf/manual.clj.html deleted file mode 100644 index b80738c..0000000 --- a/docs/cloverage/beowulf/manual.clj.html +++ /dev/null @@ -1,2315 +0,0 @@ - - - - beowulf/manual.clj - - - - 001  (ns beowulf.manual -
- - 002    "Experimental code for accessing the manual online." -
- - 003    (:require [clojure.string :refer [ends-with? join trim]])) -
- - 004   -
- - 005  (def ^:dynamic *manual-url* -
- - 006    "https://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf") -
- - 007   -
- - 008  (def ^:constant index -
- - 009    "This is data extracted from the index pages of `Lisp 1.5 Programmer's Manual`. -
- - 010     It's here in the hope that we can automatically link to an online PDF link -
- - 011     to the manual when the user invokes a function probably called `DOC` or `HELP`." -
- - 012    {:RECIP -
- - 013     {:fn-name "RECIP", -
- - 014      :call-type "SUBR", -
- - 015      :implementation "", -
- - 016      :page-nos ["26" "64"]}, -
- - 017     :QUOTE -
- - 018     {:fn-name "QUOTE", -
- - 019      :call-type "FSUBR", -
- - 020      :implementation "", -
- - 021      :page-nos ["10" "22" "71"]}, -
- - 022     :RECLAIM -
- - 023     {:fn-name "RECLAIM", -
- - 024      :call-type "SUBR", -
- - 025      :implementation "PSEUDO-FUNCTION ", -
- - 026      :page-nos ["67"]}, -
- - 027     :NUMOB -
- - 028     {:fn-name "NUMOB", -
- - 029      :call-type "SUBR", -
- - 030      :implementation "PSEUDO-FUNCTION ", -
- - 031      :page-nos ["86"]}, -
- - 032     :EVLIS -
- - 033     {:fn-name "EVLIS", -
- - 034      :call-type "SUBR", -
- - 035      :implementation "", -
- - 036      :page-nos ["71"]}, -
- - 037     :DASH -
- - 038     {:fn-name "DASH", -
- - 039      :call-type "SUBR", -
- - 040      :implementation "PREDICATE APVAL", -
- - 041      :page-nos ["85" "87 "]}, -
- - 042     :EQUAL -
- - 043     {:fn-name "EQUAL", -
- - 044      :call-type "SUBR", -
- - 045      :implementation "PREDICATE", -
- - 046      :page-nos ["11" "26" "57"]}, -
- - 047     :PRIN1 -
- - 048     {:fn-name "PRIN1", -
- - 049      :call-type "SUBR", -
- - 050      :implementation "PSEUDO-FUNCTION ", -
- - 051      :page-nos ["65" "84"]}, -
- - 052     :REMFLAG -
- - 053     {:fn-name "REMFLAG", -
- - 054      :call-type "SUBR", -
- - 055      :implementation "PSEUDO-FUNCTION ", -
- - 056      :page-nos ["41" "60"]}, -
- - 057     :DEFINE -
- - 058     {:fn-name "DEFINE", -
- - 059      :call-type "EXPR", -
- - 060      :implementation "PSEUDO-FUNCTION", -
- - 061      :page-nos ["15" "18" "58"]}, -
- - 062     :PUNCHLAP -
- - 063     {:fn-name "PUNCHLAP", -
- - 064      :call-type "EXPR", -
- - 065      :implementation "PSEUDO-FUNCTION LIBRARY", -
- - 066      :page-nos ["68" "76"]}, -
- - 067     :STARTREAD -
- - 068     {:fn-name "STARTREAD", -
- - 069      :call-type "SUBR", -
- - 070      :implementation "PSEUDO-FUNCTION", -
- - 071      :page-nos ["87"]}, -
- - 072     :PERIOD -
- - 073     {:fn-name "PERIOD", -
- - 074      :call-type "APVAL", -
- - 075      :implementation "", -
- - 076      :page-nos ["69" "85"]}, -
- - 077     :CP1 -
- - 078     {:fn-name "CP1", -
- - 079      :call-type "SUBR", -
- - 080      :implementation "", -
- - 081      :page-nos ["66"]}, -
- - 082     :NCONC -
- - 083     {:fn-name "NCONC", -
- - 084      :call-type "SUBR", -
- - 085      :implementation "PSEUDO-FUNCTION ", -
- - 086      :page-nos ["62"]}, -
- - 087     :EQ -
- - 088     {:fn-name "EQ", -
- - 089      :call-type "SUBR", -
- - 090      :implementation "PREDICATE", -
- - 091      :page-nos ["3" "23" "57"]}, -
- - 092     :RPLACD -
- - 093     {:fn-name "RPLACD", -
- - 094      :call-type "SUBR", -
- - 095      :implementation "PSEUDO-FUNCTION", -
- - 096      :page-nos ["41" "58"]}, -
- - 097     :PROG2 -
- - 098     {:fn-name "PROG2", -
- - 099      :call-type "SUBR", -
- - 100      :implementation "", -
- - 101      :page-nos ["42" "66"]}, -
- - 102     :UNCOUNT -
- - 103     {:fn-name "UNCOUNT", -
- - 104      :call-type "SUBR", -
- - 105      :implementation "PSEUDO-FUNCTION", -
- - 106      :page-nos ["34" "66"]}, -
- - 107     :ERROR1 -
- - 108     {:fn-name "ERROR1", -
- - 109      :call-type "SUBR", -
- - 110      :implementation "PSEUDO-FUNCTION", -
- - 111      :page-nos ["88"]}, -
- - 112     :EXPT -
- - 113     {:fn-name "EXPT", -
- - 114      :call-type "SUBR", -
- - 115      :implementation "", -
- - 116      :page-nos ["26" "64"]}, -
- - 117     :NOT -
- - 118     {:fn-name "NOT", -
- - 119      :call-type "SUBR", -
- - 120      :implementation "PREDICATE", -
- - 121      :page-nos ["21" "23" "58"]}, -
- - 122     :SLASH -
- - 123     {:fn-name "SLASH", -
- - 124      :call-type "APVAL", -
- - 125      :implementation "", -
- - 126      :page-nos ["69" "85"]}, -
- - 127     :RPLACA -
- - 128     {:fn-name "RPLACA", -
- - 129      :call-type "SUBR", -
- - 130      :implementation "PSEUDO-FUNCTION", -
- - 131      :page-nos ["41" "58"]}, -
- - 132     :QUOTIENT -
- - 133     {:fn-name "QUOTIENT", -
- - 134      :call-type "SUBR", -
- - 135      :implementation "", -
- - 136      :page-nos ["26" "64"]}, -
- - 137     :UNPACK -
- - 138     {:fn-name "UNPACK", -
- - 139      :call-type "SUBR", -
- - 140      :implementation "PSEUDO-FUNCTION", -
- - 141      :page-nos ["87"]}, -
- - 142     :CONC -
- - 143     {:fn-name "CONC", -
- - 144      :call-type "FEXPR", -
- - 145      :implementation "", -
- - 146      :page-nos ["61"]}, -
- - 147     :CAR -
- - 148     {:fn-name "CAR", -
- - 149      :call-type "SUBR", -
- - 150      :implementation "", -
- - 151      :page-nos ["2" "56"]}, -
- - 152     :GENSYM -
- - 153     {:fn-name "GENSYM", -
- - 154      :call-type "SUBR", -
- - 155      :implementation "", -
- - 156      :page-nos ["66"]}, -
- - 157     :PROP -
- - 158     {:fn-name "PROP", -
- - 159      :call-type "SUBR", -
- - 160      :implementation "FUNCTIONAL ", -
- - 161      :page-nos [" 59"]}, -
- - 162     :MEMBER -
- - 163     {:fn-name "MEMBER", -
- - 164      :call-type "SUBR", -
- - 165      :implementation "PREDICATE ", -
- - 166      :page-nos ["11" "62"]}, -
- - 167     :UNTRACESET -
- - 168     {:fn-name "UNTRACESET", -
- - 169      :call-type "EXPR", -
- - 170      :implementation "PSEUDO-FUNCTION", -
- - 171      :page-nos ["68"]}, -
- - 172     :UNTRACE -
- - 173     {:fn-name "UNTRACE", -
- - 174      :call-type "EXPR", -
- - 175      :implementation "PSEUDO-FUNCTION", -
- - 176      :page-nos ["32" "66"]}, -
- - 177     :MINUSP -
- - 178     {:fn-name "MINUSP", -
- - 179      :call-type "SUBR", -
- - 180      :implementation "PREDICATE ", -
- - 181      :page-nos ["26" "64"]}, -
- - 182     :F -
- - 183     {:fn-name "F", -
- - 184      :call-type "APVAL", -
- - 185      :implementation "", -
- - 186      :page-nos ["22" "69"]}, -
- - 187     :SPECIAL -
- - 188     {:fn-name "SPECIAL", -
- - 189      :call-type "SUBR", -
- - 190      :implementation "PSEUDO-FUNCTION", -
- - 191      :page-nos ["64" "78"]}, -
- - 192     :LPAR -
- - 193     {:fn-name "LPAR", -
- - 194      :call-type "APVAL", -
- - 195      :implementation "", -
- - 196      :page-nos ["69" "85"]}, -
- - 197     :GO -
- - 198     {:fn-name "GO", -
- - 199      :call-type "FSUBR", -
- - 200      :implementation "PSEUDO-FUNCTION", -
- - 201      :page-nos ["30" "72"]}, -
- - 202     :MKNAM -
- - 203     {:fn-name "MKNAM", -
- - 204      :call-type "SUBR", -
- - 205      :implementation "", -
- - 206      :page-nos ["86"]}, -
- - 207     :COMMON -
- - 208     {:fn-name "COMMON", -
- - 209      :call-type "SUBR", -
- - 210      :implementation "PSEUDO-FUNCTION", -
- - 211      :page-nos ["64" "78"]}, -
- - 212     :NUMBERP -
- - 213     {:fn-name "NUMBERP", -
- - 214      :call-type "SUBR", -
- - 215      :implementation "PREDICATE ", -
- - 216      :page-nos ["26" "64"]}, -
- - 217     :CONS -
- - 218     {:fn-name "CONS", -
- - 219      :call-type "SUBR", -
- - 220      :implementation "", -
- - 221      :page-nos ["2" "56"]}, -
- - 222     :PLUS -
- - 223     {:fn-name "PLUS", -
- - 224      :call-type "FSUBR", -
- - 225      :implementation "", -
- - 226      :page-nos ["25" "63"]}, -
- - 227     :SET -
- - 228     {:fn-name "SET", -
- - 229      :call-type "SUBR", -
- - 230      :implementation "PSEUDO-FUNCTION", -
- - 231      :page-nos ["30" "71"]}, -
- - 232     :DOLLAR -
- - 233     {:fn-name "DOLLAR", -
- - 234      :call-type "APVAL", -
- - 235      :implementation "", -
- - 236      :page-nos ["69" "85"]}, -
- - 237     :SASSOC -
- - 238     {:fn-name "SASSOC", -
- - 239      :call-type "SUBR", -
- - 240      :implementation "FUNCTIONAL", -
- - 241      :page-nos ["60"]}, -
- - 242     :SELECT -
- - 243     {:fn-name "SELECT", -
- - 244      :call-type "FEXPR", -
- - 245      :implementation "", -
- - 246      :page-nos ["66"]}, -
- - 247     :OPDEFINE -
- - 248     {:fn-name "OPDEFINE", -
- - 249      :call-type "EXPR", -
- - 250      :implementation "PSEUDO-FUNCTION ", -
- - 251      :page-nos ["65" "75"]}, -
- - 252     :PAUSE -
- - 253     {:fn-name "PAUSE", -
- - 254      :call-type "SUBR", -
- - 255      :implementation "PSEUDO-FUNCTION", -
- - 256      :page-nos ["67"]}, -
- - 257     :AND -
- - 258     {:fn-name "AND", -
- - 259      :call-type "FSUBR", -
- - 260      :implementation "PREDICATE", -
- - 261      :page-nos ["21" "58"]}, -
- - 262     :COMMA -
- - 263     {:fn-name "COMMA", -
- - 264      :call-type "APVAL", -
- - 265      :implementation "", -
- - 266      :page-nos ["69" "85"]}, -
- - 267     :EFFACE -
- - 268     {:fn-name "EFFACE", -
- - 269      :call-type "SUBR", -
- - 270      :implementation "PSEUDO-FUNCTION", -
- - 271      :page-nos ["63"]}, -
- - 272     :CSETQ -
- - 273     {:fn-name "CSETQ", -
- - 274      :call-type "FEXPR", -
- - 275      :implementation "PSEUDO-FUNCTION", -
- - 276      :page-nos ["59"]}, -
- - 277     :OPCHAR -
- - 278     {:fn-name "OPCHAR", -
- - 279      :call-type "SUBR", -
- - 280      :implementation "PREDICATE ", -
- - 281      :page-nos [" 87"]}, -
- - 282     :PRINTPROP -
- - 283     {:fn-name "PRINTPROP", -
- - 284      :call-type "EXPR", -
- - 285      :implementation "PSEUDO-FUNCTION LIBRARY ", -
- - 286      :page-nos ["68"]}, -
- - 287     :PLB -
- - 288     {:fn-name "PLB", -
- - 289      :call-type "SUBR", -
- - 290      :implementation "PSEUDO- FUNCTION", -
- - 291      :page-nos ["67"]}, -
- - 292     :DIGIT -
- - 293     {:fn-name "DIGIT", -
- - 294      :call-type "SUBR", -
- - 295      :implementation "PREDICATE ", -
- - 296      :page-nos ["87"]}, -
- - 297     :PUNCHDEF -
- - 298     {:fn-name "PUNCHDEF", -
- - 299      :call-type "EXPR", -
- - 300      :implementation "PSEUDO-FUNCTION LIBRARY", -
- - 301      :page-nos ["68"]}, -
- - 302     :ARRAY -
- - 303     {:fn-name "ARRAY", -
- - 304      :call-type "SUBR", -
- - 305      :implementation "PSEUDO-FUNCTION", -
- - 306      :page-nos ["27" "64"]}, -
- - 307     :MAX -
- - 308     {:fn-name "MAX", -
- - 309      :call-type "FSUBR", -
- - 310      :implementation "", -
- - 311      :page-nos ["26" "64"]}, -
- - 312     :INTERN -
- - 313     {:fn-name "INTERN", -
- - 314      :call-type "SUBR", -
- - 315      :implementation "PSEUDO-FUNCTION", -
- - 316      :page-nos ["67" "87"]}, -
- - 317     :NIL -
- - 318     {:fn-name "NIL", -
- - 319      :call-type "APVAL", -
- - 320      :implementation "", -
- - 321      :page-nos ["22" "69"]}, -
- - 322     :TIMES -
- - 323     {:fn-name "TIMES", -
- - 324      :call-type "FSUBR", -
- - 325      :implementation "", -
- - 326      :page-nos ["26" "64"]}, -
- - 327     :ERROR -
- - 328     {:fn-name "ERROR", -
- - 329      :call-type "SUBR", -
- - 330      :implementation "PSEUDO-FUNCTION", -
- - 331      :page-nos ["32" "66"]}, -
- - 332     :PUNCH -
- - 333     {:fn-name "PUNCH", -
- - 334      :call-type "SUBR", -
- - 335      :implementation "PSEUDO-FUNCTION", -
- - 336      :page-nos ["65" "84"]}, -
- - 337     :REMPROP -
- - 338     {:fn-name "REMPROP", -
- - 339      :call-type "SUBR", -
- - 340      :implementation "PSEUDO-FUNCTION", -
- - 341      :page-nos ["41" "59"]}, -
- - 342     :DIVIDE -
- - 343     {:fn-name "DIVIDE", -
- - 344      :call-type "SUBR", -
- - 345      :implementation "", -
- - 346      :page-nos ["26" "64"]}, -
- - 347     :OR -
- - 348     {:fn-name "OR", -
- - 349      :call-type "FSUBR", -
- - 350      :implementation "PREDICATE ", -
- - 351      :page-nos ["21" "58"]}, -
- - 352     :SUBLIS -
- - 353     {:fn-name "SUBLIS", -
- - 354      :call-type "SUBR", -
- - 355      :implementation "", -
- - 356      :page-nos ["12" "61"]}, -
- - 357     :LAP -
- - 358     {:fn-name "LAP", -
- - 359      :call-type "SUBR", -
- - 360      :implementation "PSEUDO-FUNCTION ", -
- - 361      :page-nos ["65" "73"]}, -
- - 362     :PROG -
- - 363     {:fn-name "PROG", -
- - 364      :call-type "FSUBR", -
- - 365      :implementation "", -
- - 366      :page-nos ["29" "71"]}, -
- - 367     :T -
- - 368     {:fn-name "T", -
- - 369      :call-type "APVAL", -
- - 370      :implementation "", -
- - 371      :page-nos ["22" "69"]}, -
- - 372     :GREATERP -
- - 373     {:fn-name "GREATERP", -
- - 374      :call-type "SUBR", -
- - 375      :implementation "PREDICATE", -
- - 376      :page-nos ["26" "64"]}, -
- - 377     :CSET -
- - 378     {:fn-name "CSET", -
- - 379      :call-type "EXPR", -
- - 380      :implementation "PSEUDO-FUNCTION", -
- - 381      :page-nos ["17" "59"]}, -
- - 382     :FUNCTION -
- - 383     {:fn-name "FUNCTION", -
- - 384      :call-type "FSUBR", -
- - 385      :implementation "", -
- - 386      :page-nos ["21" "71"]}, -
- - 387     :LENGTH -
- - 388     {:fn-name "LENGTH", -
- - 389      :call-type "SUBR", -
- - 390      :implementation "", -
- - 391      :page-nos ["62"]}, -
- - 392     :MINUS -
- - 393     {:fn-name "MINUS", -
- - 394      :call-type "SUBR", -
- - 395      :implementation "", -
- - 396      :page-nos ["26" "63"]}, -
- - 397     :COND -
- - 398     {:fn-name "COND", -
- - 399      :call-type "FSUBR", -
- - 400      :implementation "", -
- - 401      :page-nos ["18"]}, -
- - 402     :APPEND -
- - 403     {:fn-name "APPEND", -
- - 404      :call-type "SUBR", -
- - 405      :implementation "", -
- - 406      :page-nos ["11" "61"]}, -
- - 407     :CDR -
- - 408     {:fn-name "CDR", -
- - 409      :call-type "SUBR", -
- - 410      :implementation "", -
- - 411      :page-nos ["3" "56"]}, -
- - 412     :OBLIST -
- - 413     {:fn-name "OBLIST", -
- - 414      :call-type "APVAL", -
- - 415      :implementation "", -
- - 416      :page-nos ["69"]}, -
- - 417     :READ -
- - 418     {:fn-name "READ", -
- - 419      :call-type "SUBR", -
- - 420      :implementation "PSEUDO-FUNCTION ", -
- - 421      :page-nos ["5" "84"]}, -
- - 422     :ERRORSET -
- - 423     {:fn-name "ERRORSET", -
- - 424      :call-type "SUBR", -
- - 425      :implementation "PSEUDO-FUNCTION", -
- - 426      :page-nos ["35" "66"]}, -
- - 427     :UNCOMMON -
- - 428     {:fn-name "UNCOMMON", -
- - 429      :call-type "SUBR", -
- - 430      :implementation "PSEUDO-FUNCTION ", -
- - 431      :page-nos ["64" "78"]}, -
- - 432     :EVAL -
- - 433     {:fn-name "EVAL", -
- - 434      :call-type "SUBR", -
- - 435      :implementation "", -
- - 436      :page-nos ["71"]}, -
- - 437     :MIN -
- - 438     {:fn-name "MIN", -
- - 439      :call-type "FSUBR", -
- - 440      :implementation "", -
- - 441      :page-nos ["26" "64"]}, -
- - 442     :PAIR -
- - 443     {:fn-name "PAIR", -
- - 444      :call-type "SUBR", -
- - 445      :implementation "", -
- - 446      :page-nos ["60"]}, -
- - 447     :BLANK -
- - 448     {:fn-name "BLANK", -
- - 449      :call-type "APVAL", -
- - 450      :implementation "", -
- - 451      :page-nos ["69" "85"]}, -
- - 452     :SETQ -
- - 453     {:fn-name "SETQ", -
- - 454      :call-type "FSUBR", -
- - 455      :implementation "PSEUDO-FUNCTION", -
- - 456      :page-nos ["30" "71"]}, -
- - 457     :GET -
- - 458     {:fn-name "GET", -
- - 459      :call-type "SUBR", -
- - 460      :implementation "", -
- - 461      :page-nos ["41" "59"]}, -
- - 462     :PRINT -
- - 463     {:fn-name "PRINT", -
- - 464      :call-type "SUBR", -
- - 465      :implementation "PSEUDO-FUNCTION ", -
- - 466      :page-nos ["65" "84"]}, -
- - 467     :ENDREAD -
- - 468     {:fn-name "ENDREAD", -
- - 469      :call-type "SUBR", -
- - 470      :implementation "PSEUDO-FUNCTION", -
- - 471      :page-nos ["8 8"]}, -
- - 472     :RETURN -
- - 473     {:fn-name "RETURN", -
- - 474      :call-type "SUBR", -
- - 475      :implementation "PSEUDO-FUNCTION", -
- - 476      :page-nos ["30" "72"]}, -
- - 477     :LITER -
- - 478     {:fn-name "LITER", -
- - 479      :call-type "SUBR", -
- - 480      :implementation "PREDICATE ", -
- - 481      :page-nos ["87"]}, -
- - 482     :EOF -
- - 483     {:fn-name "EOF", -
- - 484      :call-type "APVAL", -
- - 485      :implementation "", -
- - 486      :page-nos ["69" "88"]}, -
- - 487     :TRACE -
- - 488     {:fn-name "TRACE", -
- - 489      :call-type "EXPR", -
- - 490      :implementation "PSEUDO-FUNCTION", -
- - 491      :page-nos ["32" "66" "79"]}, -
- - 492     :TRACESET -
- - 493     {:fn-name "TRACESET", -
- - 494      :call-type "EXPR", -
- - 495      :implementation "PSEUDO-FUNCTION LIBRARY", -
- - 496      :page-nos ["68"]}, -
- - 497     :PACK -
- - 498     {:fn-name "PACK", -
- - 499      :call-type "SUBR", -
- - 500      :implementation "PSEUDO-FUNCTION ", -
- - 501      :page-nos ["86"]}, -
- - 502     :NULL -
- - 503     {:fn-name "NULL", -
- - 504      :call-type "SUBR", -
- - 505      :implementation "PREDICATE ", -
- - 506      :page-nos ["11" "57"]}, -
- - 507     :CLEARBUFF -
- - 508     {:fn-name "CLEARBUFF", -
- - 509      :call-type "SUBR", -
- - 510      :implementation "PSEUDO-FUNCTION", -
- - 511      :page-nos ["86"]}, -
- - 512     :LESSP -
- - 513     {:fn-name "LESSP", -
- - 514      :call-type "SUBR", -
- - 515      :implementation "PREDICATE ", -
- - 516      :page-nos ["26" "64"]}, -
- - 517     :TERPRI -
- - 518     {:fn-name "TERPRI", -
- - 519      :call-type "SUBR", -
- - 520      :implementation "PSEUDO-FUNCTION", -
- - 521      :page-nos ["65" "84"]}, -
- - 522     :ONEP -
- - 523     {:fn-name "ONEP", -
- - 524      :call-type "SUBR", -
- - 525      :implementation "PREDICATE ", -
- - 526      :page-nos [" 26" "64"]}, -
- - 527     :EXCISE -
- - 528     {:fn-name "EXCISE", -
- - 529      :call-type "SUBR", -
- - 530      :implementation "PSEUDO-FUNCTION", -
- - 531      :page-nos ["67" "77"]}, -
- - 532     :REMOB -
- - 533     {:fn-name "REMOB", -
- - 534      :call-type "SUBR", -
- - 535      :implementation "PSEUDO-FUNCTION ", -
- - 536      :page-nos ["67"]}, -
- - 537     :MAP -
- - 538     {:fn-name "MAP", -
- - 539      :call-type "SUBR", -
- - 540      :implementation "FUNCTIONAL ", -
- - 541      :page-nos ["63"]}, -
- - 542     :COMPILE -
- - 543     {:fn-name "COMPILE", -
- - 544      :call-type "SUBR", -
- - 545      :implementation "PSEUDO-FUNCTION", -
- - 546      :page-nos ["64" "76"]}, -
- - 547     :ADD1 -
- - 548     {:fn-name "ADD1", -
- - 549      :call-type "SUBR", -
- - 550      :implementation "", -
- - 551      :page-nos ["26" "64"]}, -
- - 552     :ADVANCE -
- - 553     {:fn-name "ADVANCE", -
- - 554      :call-type "SUBR", -
- - 555      :implementation "PSEUDO-FUNCTION", -
- - 556      :page-nos ["88"]}, -
- - 557     :SEARCH -
- - 558     {:fn-name "SEARCH", -
- - 559      :call-type "SUBR", -
- - 560      :implementation "FUNCTIONAL", -
- - 561      :page-nos ["63"]}, -
- - 562     :APPLY -
- - 563     {:fn-name "APPLY", -
- - 564      :call-type "SUBR", -
- - 565      :implementation "", -
- - 566      :page-nos ["70"]}, -
- - 567     :READLAP -
- - 568     {:fn-name "READLAP", -
- - 569      :call-type "SUBR", -
- - 570      :implementation "PSEUDO-FUNCTION ", -
- - 571      :page-nos ["65" "76"]}, -
- - 572     :UNSPECIAL -
- - 573     {:fn-name "UNSPECIAL", -
- - 574      :call-type "SUBR", -
- - 575      :implementation "", -
- - 576      :page-nos ["64" "78"]}, -
- - 577     :SUBST -
- - 578     {:fn-name "SUBST", -
- - 579      :call-type "SUBR", -
- - 580      :implementation "", -
- - 581      :page-nos ["11" "61"]}, -
- - 582     :COPY -
- - 583     {:fn-name "COPY", -
- - 584      :call-type "SUBR", -
- - 585      :implementation "", -
- - 586      :page-nos ["62"]}, -
- - 587     :LOGOR -
- - 588     {:fn-name "LOGOR", -
- - 589      :call-type "FSUBR", -
- - 590      :implementation "", -
- - 591      :page-nos ["26" "64"]}, -
- - 592     :LABEL -
- - 593     {:fn-name "LABEL", -
- - 594      :call-type "FSUBR", -
- - 595      :implementation "", -
- - 596      :page-nos ["8" "18" "70"]}, -
- - 597     :FIXP -
- - 598     {:fn-name "FIXP", -
- - 599      :call-type "SUBR", -
- - 600      :implementation "PREDICATE", -
- - 601      :page-nos ["26" "64"]}, -
- - 602     :SUB1 -
- - 603     {:fn-name "SUB1", -
- - 604      :call-type "SUBR", -
- - 605      :implementation "", -
- - 606      :page-nos ["26" "64"]}, -
- - 607     :ATTRIB -
- - 608     {:fn-name "ATTRIB", -
- - 609      :call-type "SUBR", -
- - 610      :implementation "PSEUDO-FUNCTION", -
- - 611      :page-nos ["59"]}, -
- - 612     :DIFFERENCE -
- - 613     {:fn-name "DIFFERENCE", -
- - 614      :call-type "SUBR", -
- - 615      :implementation "", -
- - 616      :page-nos ["26" "64"]}, -
- - 617     :REMAINDER -
- - 618     {:fn-name "REMAINDER", -
- - 619      :call-type "SUBR", -
- - 620      :implementation "", -
- - 621      :page-nos ["26" "64"]}, -
- - 622     :REVERSE -
- - 623     {:fn-name "REVERSE", -
- - 624      :call-type "SUBR", -
- - 625      :implementation "", -
- - 626      :page-nos ["6 2"]}, -
- - 627     :EOR -
- - 628     {:fn-name "EOR", -
- - 629      :call-type "APVAL", -
- - 630      :implementation "", -
- - 631      :page-nos ["69" "88"]}, -
- - 632     :PLUSS -
- - 633     {:fn-name "PLUSS", -
- - 634      :call-type "APVAL", -
- - 635      :implementation "", -
- - 636      :page-nos ["69" "85"]}, -
- - 637     :TEMPUS-FUGIT -
- - 638     {:fn-name "TEMPUS-FUGIT", -
- - 639      :call-type "SUBR", -
- - 640      :implementation "PSEUDO-FUNCTION", -
- - 641      :page-nos ["67"]}, -
- - 642     :LOAD -
- - 643     {:fn-name "LOAD", -
- - 644      :call-type "SUBR", -
- - 645      :implementation "PSEUDO-FUNCTION", -
- - 646      :page-nos ["67"]}, -
- - 647     :CHARCOUNT -
- - 648     {:fn-name "CHARCOUNT", -
- - 649      :call-type "APVAL", -
- - 650      :implementation "", -
- - 651      :page-nos ["69" "87"]}, -
- - 652     :RPAR -
- - 653     {:fn-name "RPAR", -
- - 654      :call-type "APVAL", -
- - 655      :implementation "", -
- - 656      :page-nos ["69" "85"]}, -
- - 657     :COUNT -
- - 658     {:fn-name "COUNT", -
- - 659      :call-type "SUBR", -
- - 660      :implementation "PSEUDO-FUNCTION", -
- - 661      :page-nos ["34" "66"]}, -
- - 662     :SPEAK -
- - 663     {:fn-name "SPEAK", -
- - 664      :call-type "SUBR", -
- - 665      :implementation "PSEUDO-FUNCTION", -
- - 666      :page-nos ["34" "66 "]}, -
- - 667     :LOGXOR -
- - 668     {:fn-name "LOGXOR", -
- - 669      :call-type "FSUBR", -
- - 670      :implementation "", -
- - 671      :page-nos ["27" "64"]}, -
- - 672     :FLOATP -
- - 673     {:fn-name "FLOATP", -
- - 674      :call-type "SUBR", -
- - 675      :implementation "PREDICATE", -
- - 676      :page-nos ["26" "64"]}, -
- - 677     :ATOM -
- - 678     {:fn-name "ATOM", -
- - 679      :call-type "SUBR", -
- - 680      :implementation "PREDICATE", -
- - 681      :page-nos ["3" "57"]}, -
- - 682     :EQSIGN -
- - 683     {:fn-name "EQSIGN", -
- - 684      :call-type "APVAL", -
- - 685      :implementation "", -
- - 686      :page-nos ["69" "85"]}, -
- - 687     :LIST -
- - 688     {:fn-name "LIST", -
- - 689      :call-type "FSUBR", -
- - 690      :implementation "", -
- - 691      :page-nos ["57"]}, -
- - 692     :MAPLIST -
- - 693     {:fn-name "MAPLIST", -
- - 694      :call-type "SUBR", -
- - 695      :implementation "FUNCTIONAL ", -
- - 696      :page-nos ["20" "21" "63"]}, -
- - 697     :LOGAND -
- - 698     {:fn-name "LOGAND", -
- - 699      :call-type "FSUBR", -
- - 700      :implementation "", -
- - 701      :page-nos ["27" "64"]}, -
- - 702     :FLAG -
- - 703     {:fn-name "FLAG", -
- - 704      :call-type "EXPR", -
- - 705      :implementation "PSEUDO-FUNCTION", -
- - 706      :page-nos ["41" "60"]}, -
- - 707     :MAPCON -
- - 708     {:fn-name "MAPCON", -
- - 709      :call-type "SUBR", -
- - 710      :implementation "FUNCTIONAL PSEUDO- FUNCTION", -
- - 711      :page-nos ["63"]}, -
- - 712     :STAR -
- - 713     {:fn-name "STAR", -
- - 714      :call-type "APVAL", -
- - 715      :implementation "", -
- - 716      :page-nos ["69" "85"]}, -
- - 717     :CURCHAR -
- - 718     {:fn-name "CURCHAR", -
- - 719      :call-type "APVAL", -
- - 720      :implementation "", -
- - 721      :page-nos ["69" "87"]}, -
- - 722     :DUMP -
- - 723     {:fn-name "DUMP", -
- - 724      :call-type "SUBR", -
- - 725      :implementation "PSEUDO-FUNCTION", -
- - 726      :page-nos ["67"]}, -
- - 727     :DEFLIST -
- - 728     {:fn-name "DEFLIST", -
- - 729      :call-type "EXPR", -
- - 730      :implementation "PSEUDO-FUNCTION", -
- - 731      :page-nos ["41" "58"]}, -
- - 732     :LEFTSHIFT -
- - 733     {:fn-name "LEFTSHIFT", -
- - 734      :call-type "SUBR", -
- - 735      :implementation "", -
- - 736      :page-nos ["27" "64"]}, -
- - 737     :ZEROP -
- - 738     {:fn-name "ZEROP", -
- - 739      :call-type "SUBR", -
- - 740      :implementation "PREDICATE", -
- - 741      :page-nos ["26" "64"]}}) -
- - 742   -
- - 743  (defn page-url -
- - 744    "Format the URL for the page in the manual with this `page-no`." -
- - 745    [page-no] -
- - 746    (let [n (read-string page-no) -
- - 747          n' (when (and (number? n) -
- - 748                        (ends-with? *manual-url* ".pdf")) -
- - 749               ;; annoyingly, the manual has eight pages of front-matter -
- - 750               ;; before numbering starts. -
- - 751               (+ n 8))] -
- - 752      (format -
- - 753       (if (ends-with? *manual-url* ".pdf") "%s#page=%s" "%s#page%s") -
- - 754       *manual-url* -
- - 755       (or n' (trim (str page-no)))))) -
- - 756   -
- - 757  (defn format-page-references -
- - 758    "Format page references from the manual index for the function whose name -
- - 759     is `fn-symbol`." -
- - 760    [fn-symbol] -
- - 761    (let [k (if (keyword? fn-symbol) fn-symbol (keyword fn-symbol))] -
- - 762      (join ", " -
- - 763            (doall -
- - 764             (map -
- - 765              (fn [n] -
- - 766                (let [p (trim n)] -
- - 767                  (format "<a href='%s'>%s</a>" -
- - 768                          (page-url p) p))) -
- - 769              (:page-nos (index k))))))) -
- - diff --git a/docs/cloverage/beowulf/oblist.clj.html b/docs/cloverage/beowulf/oblist.clj.html deleted file mode 100644 index f96cc9c..0000000 --- a/docs/cloverage/beowulf/oblist.clj.html +++ /dev/null @@ -1,143 +0,0 @@ - - - - beowulf/oblist.clj - - - - 001  (ns beowulf.oblist -
- - 002    "A namespace mainly devoted to the object list and other top level -
- - 003     global variables. -
- - 004      -
- - 005     Yes, this makes little sense, but if you put them anywhere else you end -
- - 006     up in cyclic dependency hell." -
- - 007    ) -
- - 008   -
- - 009  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 010  ;;; -
- - 011  ;;; Copyright (C) 2022-2023 Simon Brooke -
- - 012  ;;; -
- - 013  ;;; This program is free software; you can redistribute it and/or -
- - 014  ;;; modify it under the terms of the GNU General Public License -
- - 015  ;;; as published by the Free Software Foundation; either version 2 -
- - 016  ;;; of the License, or (at your option) any later version. -
- - 017  ;;;  -
- - 018  ;;; This program is distributed in the hope that it will be useful, -
- - 019  ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -
- - 020  ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -
- - 021  ;;; GNU General Public License for more details. -
- - 022  ;;;  -
- - 023  ;;; You should have received a copy of the GNU General Public License -
- - 024  ;;; along with this program; if not, write to the Free Software -
- - 025  ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. -
- - 026  ;;; -
- - 027  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 028   -
- - 029  (def NIL -
- - 030    "The canonical empty list symbol. -
- - 031      -
- - 032     TODO: this doesn't really work, because (from Clojure) `(empty? NIL)` throws -
- - 033     an exception. It might be better to subclass beowulf.cons_cell.ConsCell to create -
- - 034     a new singleton class Nil which overrides the `empty` method of  -
- - 035     IPersistentCollection?" -
- - 036    'NIL) -
- - 037   -
- - 038  (def oblist -
- - 039    "The default environment." -
- - 040    (atom NIL)) -
- - 041   -
- - 042  (def ^:dynamic *options* -
- - 043    "Command line options from invocation." -
- - 044    {}) -
- - 045   -
- - diff --git a/docs/cloverage/beowulf/read.clj.html b/docs/cloverage/beowulf/read.clj.html index ba3a47f..f999f3a 100644 --- a/docs/cloverage/beowulf/read.clj.html +++ b/docs/cloverage/beowulf/read.clj.html @@ -35,7 +35,7 @@ 010        reader ever did;

- 011    2. It treats everything between a double semi-colon and an end of line as a comment, + 011    2. It treats everything between a semi-colon and an end of line as a comment,
012        as most modern Lisps do; but I do not believe Lisp 1.5 had this feature. @@ -50,283 +50,904 @@ 015    switch."
- 016    (:require ;; [beowulf.reader.char-reader :refer [read-chars]] + 016    (:require [beowulf.bootstrap :refer [*options*]]
- 017              [beowulf.reader.generate :refer [generate]] + 017              [clojure.math.numeric-tower :refer [expt]]
- 018              [beowulf.reader.parser :refer [parse]] + 018              [clojure.string :refer [starts-with? upper-case]]
- 019              [beowulf.reader.simplify :refer [simplify]] + 019              [instaparse.core :as i]
- 020              [clojure.string :refer [join split starts-with? trim]]) -
- - 021    (:import [java.io InputStream] -
- - 022             [instaparse.gll Failure])) + 020              [beowulf.cons-cell :refer [make-beowulf-list make-cons-cell NIL]]))
- 023   + 021  
- 024  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + 022  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- 025  ;;; + 023  ;;;
- 026  ;;; This file provides the reader required for boostrapping. It's not a bad + 024  ;;; This file provides the reader required for boostrapping. It's not a bad
- 027  ;;; reader - it provides feedback on errors found in the input - but it isn't + 025  ;;; reader - it provides feedback on errors found in the input - but it isn't
- 028  ;;; the real Lisp reader. + 026  ;;; the real Lisp reader.
- 029  ;;; + 027  ;;;
- 030  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 031  ;;; -
- - 032  ;;; Copyright (C) 2022-2023 Simon Brooke -
- - 033  ;;; -
- - 034  ;;; This program is free software; you can redistribute it and/or -
- - 035  ;;; modify it under the terms of the GNU General Public License -
- - 036  ;;; as published by the Free Software Foundation; either version 2 -
- - 037  ;;; of the License, or (at your option) any later version. -
- - 038  ;;;  -
- - 039  ;;; This program is distributed in the hope that it will be useful, -
- - 040  ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -
- - 041  ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -
- - 042  ;;; GNU General Public License for more details. -
- - 043  ;;;  -
- - 044  ;;; You should have received a copy of the GNU General Public License -
- - 045  ;;; along with this program; if not, write to the Free Software -
- - 046  ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. -
- - 047  ;;; -
- - 048  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + 028  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- 049   + 029   +
+ + 030  (declare generate) +
+ + 031  
- 050  (defn strip-line-comments + 032  (def parse
- 051    "Strip blank lines and comment lines from this string `s`, expected to + 033    "Parse a string presented as argument into a parse tree which can then
- 052     be Lisp source." + 034    be operated upon further." +
+ + 035    (i/parser +
+ + 036      (str
- 053    [^String s] + 037        ;; top level: we accept mexprs as well as sexprs.
- - 054    (join "\n" -
- - 055          (remove -
- - 056           #(or (empty? %) -
- - 057                (starts-with? (trim %) ";;")) -
- - 058           (split s #"\n")))) + + 038        "expr := mexpr | sexpr;"
- 059   -
- - 060  (defn number-lines + 039  
- 061    ([^String s] -
- - 062     (number-lines s nil)) + 040        ;; mexprs. I'm pretty clear that Lisp 1.5 could never read these,
- 063    ([^String s ^Failure e] + 041        ;; but it's a convenience.
- - 064     (let [l (-> e :line) + + 042        "mexpr := λexpr | fncall | defn | cond | mvar | mexpr comment;
- - 065           c (-> e :column)] + + 043        λexpr := λ lsqb bindings semi-colon body rsqb;
- - 066       (join "\n" + + 044        λ := 'λ';
- - 067             (map #(str (format "%5d %s" (inc %1) %2) + + 045        bindings := lsqb args rsqb;
- - 068                        (when (= l (inc %1)) + + 046        body := (expr semi-colon opt-space)* expr;
- - 069                          (str "\n" (apply str (repeat c " ")) "^"))) + + 047        fncall := fn-name lsqb args rsqb;
- - 070                  (range) + + 048        lsqb := '[';
- - 071                  (split s #"\n")))))) + + 049        rsqb := ']'; +
+ + 050        defn := mexpr opt-space '=' opt-space mexpr; +
+ + 051        cond := lsqb (cond-clause semi-colon opt-space)* cond-clause rsqb; +
+ + 052        cond-clause := expr opt-space arrow opt-space expr; +
+ + 053        arrow := '->'; +
+ + 054        args := (expr semi-colon opt-space)* expr; +
+ + 055        fn-name := mvar; +
+ + 056        mvar := #'[a-z]+'; +
+ + 057        semi-colon := ';';"
- 072   + 058   +
+ + 059        ;; comments. I'm pretty confident Lisp 1.5 did NOT have these. +
+ + 060        "comment := opt-space <';;'> #'[^\\n\\r]*';" +
+ + 061   +
+ + 062        ;; sexprs. Note it's not clear to me whether Lisp 1.5 had the quote macro, +
+ + 063        ;; but I've included it on the basis that it can do little harm. +
+ + 064        "sexpr := quoted-expr | atom | number | dotted-pair | list | sexpr comment; +
+ + 065        list := lpar sexpr rpar | lpar (sexpr sep)* rpar | lpar (sexpr sep)* dot-terminal; +
+ + 066        dotted-pair := lpar dot-terminal ; +
+ + 067        dot := '.'; +
+ + 068        lpar := '('; +
+ + 069        rpar := ')'; +
+ + 070        quoted-expr := quote sexpr; +
+ + 071        quote := '\\''; +
+ + 072        dot-terminal := sexpr space dot space sexpr rpar; +
+ + 073        space := #'\\p{javaWhitespace}+'; +
+ + 074        opt-space := #'\\p{javaWhitespace}*'; +
+ + 075        sep := ',' | opt-space; +
+ + 076        atom := #'[A-Z][A-Z0-9]*';" +
+ + 077   +
+ + 078        ;; Lisp 1.5 supported octal as well as decimal and scientific notation +
+ + 079        "number := integer | decimal | scientific | octal; +
+ + 080        integer := #'-?[1-9][0-9]*'; +
+ + 081        decimal := #'-?[1-9][0-9]*\\.?[0-9]*' | #'0.[0-9]*'; +
+ + 082        scientific := coefficient e exponent; +
+ + 083        coefficient := decimal; +
+ + 084        exponent := integer; +
+ + 085        e := 'E'; +
+ + 086        octal := #'[+-]?[0-7]+{1,12}' q scale-factor; +
+ + 087        q := 'Q'; +
+ + 088        scale-factor := #'[0-9]*'"))) +
+ + 089  
- 073  (defn gsp + 090  (defn simplify
- 074    "Shortcut macro - the internals of read; or, if you like, read-string. + 091    "Simplify this parse tree `p`. If `p` is an instaparse failure object, throw
- 075    Argument `s` should be a string representation of a valid Lisp + 092    an `ex-info`, with `p` as the value of its `:failure` key."
- 076    expression." + 093    ([p]
- - 077    [s] + + 094     (if
- 078    (let [source (strip-line-comments s) -
- - 079          parse-tree (parse source)] -
- - 080      (if (instance? Failure parse-tree) -
- - 081        (doall (println (number-lines source parse-tree)) + 095       (instance? instaparse.gll.Failure p)
- 082               (throw (ex-info "Ne can forstande " (assoc parse-tree :source source)))) + 096       (throw (ex-info "Ic ne behæfd" {:cause :parse-failure :failure p}))
- - 083        (generate (simplify parse-tree))))) + + 097       (simplify p :sexpr)))
- - 084   + + 098    ([p context]
- 085  (defn read-from-console -
- - 086    "Attempt to read a complete lisp expression from the console. NOTE that this -
- - 087     will only really work for S-Expressions, not M-Expressions." -
- - 088    [] + 099    (if
- 089    (loop [r (read-line)] + 100      (coll? p)
- - 090      (if (and (= (count (re-seq #"\(" r)) -
- - 091             (count (re-seq #"\)" r))) -
- - 092               (= (count (re-seq #"\[" r)) -
- - 093                  (count (re-seq #"\]" r)))) + + 101      (apply
- 094        r + 102        vector +
+ + 103        (remove +
+ + 104          #(if (coll? %) (empty? %)) +
+ + 105          (case (first p) +
+ + 106            (:arg :expr :coefficient :fn-name :number :sexpr) (simplify (second p) context) +
+ + 107            (:λexpr +
+ + 108              :args :bindings :body :cond :cond-clause :dot-terminal +
+ + 109              :fncall :octal :quoted-expr :scientific) (map #(simplify % context) p) +
+ + 110            (:arrow :dot :e :lpar :lsqb :opt-space :q :quote :rpar :rsqb +
+ + 111              :semi-colon :sep :space) nil +
+ + 112            :atom (if +
+ + 113                    (= context :mexpr) +
+ + 114                    [:quoted-expr p] +
+ + 115                    p)
- 095        (recur (str r "\n" (read-line)))))) + 116            :comment (if
- - 096   + + 117                       (:strict *options*)
- - 097  (defn READ + + 118                       (throw
- - 098    "An implementation of a Lisp reader sufficient for bootstrapping; not necessarily + + 119                         (ex-info "Cannot parse comments in strict mode"
- - 099    the final Lisp reader. `input` should be either a string representation of a LISP + + 120                                  {:cause :strict})))
- - 100    expression, or else an input stream. A single form will be read." -
- - 101    ([] + + 121            :dotted-pair (if
- 102     (gsp (read-from-console))) + 122                           (= context :mexpr)
- - 103    ([input] + + 123                           [:fncall
- - 104     (cond + + 124                            [:mvar "cons"]
- - 105       (empty? input) (READ) + + 125                            [:args +
+ + 126                             (simplify (nth p 1) context) +
+ + 127                             (simplify (nth p 2) context)]] +
+ + 128                           (map simplify p)) +
+ + 129            :mexpr (if +
+ + 130                     (:strict *options*) +
+ + 131                     (throw +
+ + 132                       (ex-info "Cannot parse meta expressions in strict mode" +
+ + 133                                {:cause :strict}))
- 106       (string? input) (gsp input) + 134                     (simplify (second p) :mexpr))
- - 107       (instance? InputStream input) (READ (slurp input)) + + 135            :list (if
- - 108       :else    (throw (ex-info "READ: `input` should be a string or an input stream" {}))))) + + 136                    (= context :mexpr) +
+ + 137                    [:fncall +
+ + 138                     [:mvar "list"] +
+ + 139                     [:args (apply vector (map simplify (rest p)))]] +
+ + 140                    (map #(simplify % context) p)) +
+ + 141            ;;default +
+ + 142            p))) +
+ + 143      p))) +
+ + 144   +
+ + 145   +
+ + 146  ;; # From Lisp 1.5 Programmers Manual, page 10 +
+ + 147  ;; Note that I've retyped much of this, since copy/pasting out of PDF is less +
+ + 148  ;; than reliable. Any typos are mine. Quote starts [[ +
+ + 149   +
+ + 150  ;; We are now in a position to define the universal LISP function +
+ + 151  ;; evalquote[fn;args], When evalquote is given a function and a list of arguments +
+ + 152  ;; for that function, it computes the value of the function applied to the arguments. +
+ + 153  ;; LISP functions have S-expressions as arguments. In particular, the argument "fn" +
+ + 154  ;; of the function evalquote must be an S-expression. Since we have been +
+ + 155  ;; writing functions as M-expressions, it is necessary to translate them into +
+ + 156  ;; S-expressions. +
+ + 157   +
+ + 158  ;; The following rules define a method of translating functions written in the +
+ + 159  ;; meta-language into S-expressions. +
+ + 160  ;; 1. If the function is represented by its name, it is translated by changing +
+ + 161  ;;    all of the letters to upper case, making it an atomic symbol. Thus is +
+ + 162  ;;    translated to CAR. +
+ + 163  ;; 2. If the function uses the lambda notation, then the expression +
+ + 164  ;;    λ[[x ..;xn]; ε] is translated into (LAMBDA (X1 ...XN) ε*), where ε* is the translation +
+ + 165  ;;    of ε. +
+ + 166  ;; 3. If the function begins with label, then the translation of +
+ + 167  ;;    label[α;ε] is (LABEL α* ε*). +
+ + 168   +
+ + 169  ;; Forms are translated as follows: +
+ + 170  ;; 1. A variable, like a function name, is translated by using uppercase letters. +
+ + 171  ;;    Thus the translation of varl is VAR1. +
+ + 172  ;; 2. The obvious translation of letting a constant translate into itself will not +
+ + 173  ;;    work. Since the translation of x is X, the translation of X must be something +
+ + 174  ;;    else to avoid ambiguity. The solution is to quote it. Thus X is translated +
+ + 175  ;;    into (QUOTE X). +
+ + 176  ;; 3. The form fn[argl;. ..;argn] is translated into (fn* argl* ...argn*) +
+ + 177  ;; 4. The conditional expression [pl-el;...;pn-en] is translated into +
+ + 178  ;;    (COND (p1* e1*)...(pn* en*)) +
+ + 179   +
+ + 180  ;; ## Examples +
+ + 181   +
+ + 182  ;; M-expressions                                S-expressions +
+ + 183  ;; x                                            X +
+ + 184  ;; car                                          CAR +
+ + 185  ;; car[x]                                       (CAR X) +
+ + 186  ;; T                                            (QUOTE T) +
+ + 187  ;; ff[car [x]]                                  (FF (CAR X)) +
+ + 188  ;; [atom[x]->x; T->ff[car[x]]]                  (COND ((ATOM X) X) +
+ + 189  ;;                                                ((QUOTE T)(FF (CAR X)))) +
+ + 190  ;; label[ff;λ[[x];[atom[x]->x; T->ff[car[x]]]]] (LABEL FF (LAMBDA (X) (COND +
+ + 191  ;;                                                ((ATOM X) X) +
+ + 192  ;;                                                ((QUOTE T)(FF (CAR X)))))) +
+ + 193   +
+ + 194  ;; ]] quote ends +
+ + 195   +
+ + 196  (defn gen-cond-clause +
+ + 197    "Generate a cond clause from this simplified parse tree fragment `p`; +
+ + 198    returns `nil` if `p` does not represent a cond clause." +
+ + 199    [p] +
+ + 200    (if +
+ + 201      (and (coll? p)(= :cond-clause (first p))) +
+ + 202      (make-beowulf-list +
+ + 203        (list (generate (nth p 1)) +
+ + 204                       (generate (nth p 2)))))) +
+ + 205   +
+ + 206  (defn gen-cond +
+ + 207    "Generate a cond statement from this simplified parse tree fragment `p`; +
+ + 208    returns `nil` if `p` does not represent a (MEXPR) cond statement." +
+ + 209    [p] +
+ + 210    (if +
+ + 211      (and (coll? p)(= :cond (first p))) +
+ + 212      (make-beowulf-list +
+ + 213        (cons +
+ + 214          'COND +
+ + 215          (map +
+ + 216            gen-cond-clause +
+ + 217            (rest p)))))) +
+ + 218   +
+ + 219  (defn gen-fn-call +
+ + 220    "Generate a function call from this simplified parse tree fragment `p`; +
+ + 221    returns `nil` if `p` does not represent a (MEXPR) function call." +
+ + 222    [p] +
+ + 223    (if +
+ + 224      (and (coll? p)(= :fncall (first p))(= :mvar (first (second p)))) +
+ + 225      (make-cons-cell +
+ + 226        (generate (second p)) +
+ + 227        (generate (nth p 2))))) +
+ + 228   +
+ + 229   +
+ + 230  (defn gen-dot-terminated-list +
+ + 231    "Generate a list, which may be dot-terminated, from this partial parse tree +
+ + 232    'p'. Note that the function acts recursively and progressively decapitates +
+ + 233    its argument, so that the argument will not always be a valid parse tree." +
+ + 234    [p] +
+ + 235    (cond +
+ + 236      (empty? p) +
+ + 237      NIL +
+ + 238      (and (coll? (first p)) (= :dot-terminal (first (first p)))) +
+ + 239      (let [dt (first p)] +
+ + 240        (make-cons-cell +
+ + 241          (generate (nth dt 1)) +
+ + 242          (generate (nth dt 2)))) +
+ + 243      :else +
+ + 244      (make-cons-cell +
+ + 245        (generate (first p)) +
+ + 246        (gen-dot-terminated-list (rest p))))) +
+ + 247   +
+ + 248   +
+ + 249  (defn strip-leading-zeros +
+ + 250    "`read-string` interprets strings with leading zeros as octal; strip +
+ + 251    any from this string `s`. If what's left is empty (i.e. there were +
+ + 252    only zeros, return `\"0\"`." +
+ + 253    ([s] +
+ + 254     (strip-leading-zeros s "")) +
+ + 255    ([s prefix] +
+ + 256     (if +
+ + 257       (empty? s) "0" +
+ + 258       (case (first s) +
+ + 259         (\+ \-)(strip-leading-zeros (subs s 1) (str (first s) prefix)) +
+ + 260         "0" (strip-leading-zeros (subs s 1) prefix) +
+ + 261         (str prefix s))))) +
+ + 262   +
+ + 263  (defn generate +
+ + 264    "Generate lisp structure from this parse tree `p`. It is assumed that +
+ + 265    `p` has been simplified." +
+ + 266    [p] +
+ + 267    (if +
+ + 268      (coll? p) +
+ + 269      (case (first p) +
+ + 270        :λ "LAMBDA" +
+ + 271        :λexpr (make-cons-cell +
+ + 272                 (generate (nth p 1)) +
+ + 273                 (make-cons-cell (generate (nth p 2)) +
+ + 274                                 (generate (nth p 3)))) +
+ + 275        (:args :list) (gen-dot-terminated-list (rest p)) +
+ + 276        :atom (symbol (second p)) +
+ + 277        :bindings (generate (second p)) +
+ + 278        :body (make-beowulf-list (map generate (rest p))) +
+ + 279        :cond (gen-cond p) +
+ + 280        (:decimal :integer) (read-string (strip-leading-zeros (second p))) +
+ + 281        :dotted-pair (make-cons-cell +
+ + 282                       (generate (nth p 1)) +
+ + 283                       (generate (nth p 2))) +
+ + 284        :exponent (generate (second p)) +
+ + 285        :fncall (gen-fn-call p) +
+ + 286        :mvar (symbol (upper-case (second p))) +
+ + 287        :octal (let [n (read-string (strip-leading-zeros (second p) "0")) +
+ + 288                     scale (generate (nth p 2))] +
+ + 289                 (* n (expt 8 scale))) +
+ + 290   +
+ + 291        ;; the quote read macro (which probably didn't exist in Lisp 1.5, but...) +
+ + 292        :quoted-expr (make-beowulf-list (list 'QUOTE (generate (second p)))) +
+ + 293        :scale-factor (if +
+ + 294                        (empty? (second p)) 0 +
+ + 295                        (read-string (strip-leading-zeros (second p)))) +
+ + 296        :scientific (let [n (generate (second p)) +
+ + 297                          exponent (generate (nth p 2))] +
+ + 298                      (* n (expt 10 exponent))) +
+ + 299   +
+ + 300        ;; default +
+ + 301        (throw (Exception. (str "Cannot yet generate " (first p))))) +
+ + 302      p)) +
+ + 303   +
+ + 304  (defmacro gsp +
+ + 305    "Shortcut macro - the internals of read; or, if you like, read-string. +
+ + 306    Argument `s` should be a string representation of a valid Lisp +
+ + 307    expression." +
+ + 308    [s] +
+ + 309    `(generate (simplify (parse ~s)))) +
+ + 310   +
+ + 311  (defn READ +
+ + 312    "An implementation of a Lisp reader sufficient for bootstrapping; not necessarily +
+ + 313    the final Lisp reader." +
+ + 314    [input] +
+ + 315    (gsp (or input (read-line))))
diff --git a/docs/cloverage/beowulf/reader/char_reader.clj.html b/docs/cloverage/beowulf/reader/char_reader.clj.html deleted file mode 100644 index f198c42..0000000 --- a/docs/cloverage/beowulf/reader/char_reader.clj.html +++ /dev/null @@ -1,233 +0,0 @@ - - - - beowulf/reader/char_reader.clj - - - - 001  (ns beowulf.reader.char-reader -
- - 002    "Provide sensible line editing, auto completion, and history recall. -
- - 003      -
- - 004     None of what's needed here is really working yet, and a pull request with -
- - 005     a working implementation would be greatly welcomed. -
- - 006      -
- - 007     ## What's needed (rough specification) -
- - 008      -
- - 009     1. Carriage return **does not** cause input to be returned, **unless** -
- - 010         a. the number of open brackets `(` and closing brackets `)` match; and -
- - 011         b. the number of open square brackets `[` and closing square brackets `]` also match; -
- - 012     2. <Ctrl-D> aborts editing and returns the string `STOP`; -
- - 013     3. <Up-arrow> and <down-arrow> scroll back and forward through history, but ideally I'd like  -
- - 014        this to be the Lisp history (i.e. the history of S-Expressions actually read by `READ`,  -
- - 015        rather than the strings which were supplied to `READ`); -
- - 016     4. <Tab> offers potential auto-completions taken from the value of `(OBLIST)`, ideally the -
- - 017        current value, not the value at the time the session started; -
- - 018     5. <Back-arrow> and <Forward-arrow> offer movement and editing within the line. -
- - 019      -
- - 020     TODO: There are multiple problems with JLine; a better solution might be -
- - 021     to start from here: -
- - 022     https://stackoverflow.com/questions/7931988/how-to-manipulate-control-characters" -
- - 023    ;; (:import [org.jline.reader LineReader LineReaderBuilder] -
- - 024    ;;          [org.jline.terminal TerminalBuilder]) -
- - 025    ) -
- - 026   -
- - 027  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 028  ;;; -
- - 029  ;;; Copyright (C) 2022-2023 Simon Brooke -
- - 030  ;;; -
- - 031  ;;; This program is free software; you can redistribute it and/or -
- - 032  ;;; modify it under the terms of the GNU General Public License -
- - 033  ;;; as published by the Free Software Foundation; either version 2 -
- - 034  ;;; of the License, or (at your option) any later version. -
- - 035  ;;;  -
- - 036  ;;; This program is distributed in the hope that it will be useful, -
- - 037  ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -
- - 038  ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -
- - 039  ;;; GNU General Public License for more details. -
- - 040  ;;;  -
- - 041  ;;; You should have received a copy of the GNU General Public License -
- - 042  ;;; along with this program; if not, write to the Free Software -
- - 043  ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. -
- - 044  ;;; -
- - 045  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 046   -
- - 047  ;; It looks from the example given [here](https://github.com/jline/jline3/blob/master/demo/src/main/java/org/jline/demo/Repl.java) -
- - 048  ;; as though JLine could be used to build a perfect line-reader for Beowulf; but it also -
- - 049  ;; looks as though you'd need a DPhil in JLine to write it, and I don't have -
- - 050  ;; the time. -
- - 051   -
- - 052  ;; (def get-reader -
- - 053  ;;   "Return a reader, first constructing it if necessary. -
- - 054      -
- - 055  ;;    **NOTE THAT** this is not settled API. The existence and call signature of -
- - 056  ;;    this function is not guaranteed in future versions." -
- - 057  ;;   (memoize (fn [] -
- - 058  ;;   (let [term (.build (.system (TerminalBuilder/builder) true))] -
- - 059  ;;     (.build (.terminal (LineReaderBuilder/builder) term)))))) -
- - 060   -
- - 061  ;; (defn read-chars -
- - 062  ;;   "A drop-in replacement for `clojure.core/read-line`, except that line editing -
- - 063  ;;    and history should be enabled. -
- - 064      -
- - 065  ;;    **NOTE THAT** this does not work yet, but it is in the API because I hope  -
- - 066  ;;    that it will work later!" -
- - 067  ;;   []  -
- - 068  ;;     (let [eddie (get-reader)] -
- - 069  ;;       (loop [s (.readLine eddie)] -
- - 070  ;;       (if (and (= (count (re-seq #"\(" s)) -
- - 071  ;;            (count (re-seq #"\)" s))) -
- - 072  ;;                (= (count (re-seq #"\[]" s)) -
- - 073  ;;                   (count (re-seq #"\]" s)))) -
- - 074  ;;         s -
- - 075  ;;         (recur (str s " " (.readLine eddie))))))) -
- - diff --git a/docs/cloverage/beowulf/reader/generate.clj.html b/docs/cloverage/beowulf/reader/generate.clj.html deleted file mode 100644 index a1be840..0000000 --- a/docs/cloverage/beowulf/reader/generate.clj.html +++ /dev/null @@ -1,836 +0,0 @@ - - - - beowulf/reader/generate.clj - - - - 001  (ns beowulf.reader.generate -
- - 002    "Generating S-Expressions from parse trees.  -
- - 003      -
- - 004     ## From Lisp 1.5 Programmers Manual, page 10 -
- - 005     *Note that I've retyped much of this, since copy/pasting out of PDF is less -
- - 006     than reliable. Any typos are mine.* -
- - 007      -
- - 008     *Quote starts:* -
- - 009   -
- - 010     We are now in a position to define the universal LISP function -
- - 011     `evalquote[fn;args]`, When evalquote is given a function and a list of arguments -
- - 012     for that function, it computes the value of the function applied to the arguments. -
- - 013     LISP functions have S-expressions as arguments. In particular, the argument `fn` -
- - 014     of the function evalquote must be an S-expression. Since we have been -
- - 015     writing functions as M-expressions, it is necessary to translate them into -
- - 016     S-expressions. -
- - 017   -
- - 018     The following rules define a method of translating functions written in the -
- - 019     meta-language into S-expressions. -
- - 020     1. If the function is represented by its name, it is translated by changing -
- - 021        all of the letters to upper case, making it an atomic symbol. Thus `car` is  -
- - 022        translated to `CAR`. -
- - 023     2. If the function uses the lambda notation, then the expression -
- - 024        `λ[[x ..;xn]; ε]` is translated into `(LAMBDA (X1 ...XN) ε*)`, where ε* is the translation -
- - 025        of ε. -
- - 026     3. If the function begins with label, then the translation of -
- - 027        `label[α;ε]` is `(LABEL α* ε*)`. -
- - 028   -
- - 029     Forms are translated as follows: -
- - 030     1. A variable, like a function name, is translated by using uppercase letters. -
- - 031        Thus the translation of `var1` is `VAR1`. -
- - 032     2. The obvious translation of letting a constant translate into itself will not -
- - 033        work. Since the translation of `x` is `X`, the translation of `X` must be something -
- - 034        else to avoid ambiguity. The solution is to quote it. Thus `X` is translated -
- - 035        into `(QUOTE X)`. -
- - 036     3. The form `fn[argl;. ..;argn]` is translated into `(fn* argl* ...argn*)` -
- - 037     4. The conditional expression `[pl-el;...;pn-en]` is translated into -
- - 038        `(COND (p1* e1*)...(pn* en*))` -
- - 039   -
- - 040     ## Examples -
- - 041     ``` -
- - 042       M-expressions                                  S-expressions              -
- - 043     -
- - 044       x                                              X                          -
- - 045       car                                            CAR                        -
- - 046       car[x]                                         (CAR X)                    -
- - 047       T                                              (QUOTE T)                  -
- - 048       ff[car [x]]                                    (FF (CAR X))               -
- - 049       [atom[x]->x; T->ff[car[x]]]                    (COND ((ATOM X) X)  -
- - 050                                                          ((QUOTE T)(FF (CAR X)))) -
- - 051       label[ff;λ[[x];[atom[x]->x;                    (LABEL FF (LAMBDA (X)  -
- - 052            T->ff[car[x]]]]]                              (COND ((ATOM X) X)  -
- - 053                                                              ((QUOTE T)(FF (CAR X)))))) -
- - 054     ``` -
- - 055   -
- - 056     *quote ends* -
- - 057  " -
- - 058    (:require [beowulf.cons-cell :refer [make-beowulf-list make-cons-cell]] -
- - 059              [beowulf.reader.macros :refer [expand-macros]] -
- - 060              [beowulf.oblist :refer [NIL]] -
- - 061              [clojure.math.numeric-tower :refer [expt]] -
- - 062              [clojure.string :refer [upper-case]] -
- - 063              [clojure.tools.trace :refer [deftrace]])) -
- - 064   -
- - 065  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 066  ;;; -
- - 067  ;;; Copyright (C) 2022-2023 Simon Brooke -
- - 068  ;;; -
- - 069  ;;; This program is free software; you can redistribute it and/or -
- - 070  ;;; modify it under the terms of the GNU General Public License -
- - 071  ;;; as published by the Free Software Foundation; either version 2 -
- - 072  ;;; of the License, or (at your option) any later version. -
- - 073  ;;;  -
- - 074  ;;; This program is distributed in the hope that it will be useful, -
- - 075  ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -
- - 076  ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -
- - 077  ;;; GNU General Public License for more details. -
- - 078  ;;;  -
- - 079  ;;; You should have received a copy of the GNU General Public License -
- - 080  ;;; along with this program; if not, write to the Free Software -
- - 081  ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. -
- - 082  ;;; -
- - 083  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 084   -
- - 085  (declare generate) -
- - 086   -
- - 087  (defn gen-cond-clause -
- - 088    "Generate a cond clause from this simplified parse tree fragment `p`; -
- - 089    returns `nil` if `p` does not represent a cond clause." -
- - 090    [p context] -
- - 091    (when -
- - 092     (and (coll? p) (= :cond-clause (first p))) -
- - 093      (make-beowulf-list -
- - 094       (list (if (= (nth p 1) [:quoted-expr [:atom "T"]]) -
- - 095               'T -
- - 096               (generate (nth p 1) context)) -
- - 097             (generate (nth p 2) context))))) -
- - 098   -
- - 099  (defn gen-cond -
- - 100    "Generate a cond statement from this simplified parse tree fragment `p`; -
- - 101    returns `nil` if `p` does not represent a (MEXPR) cond statement." -
- - 102    [p context] -
- - 103    (when -
- - 104     (and (coll? p) (= :cond (first p))) -
- - 105      (make-beowulf-list -
- - 106       (cons -
- - 107        'COND -
- - 108        (map -
- - 109         #(generate % (if (= context :mexpr) :cond-mexpr context)) -
- - 110         (rest p)))))) -
- - 111   -
- - 112  (defn gen-fn-call -
- - 113    "Generate a function call from this simplified parse tree fragment `p`; -
- - 114    returns `nil` if `p` does not represent a (MEXPR) function call." -
- - 115    [p context] -
- - 116    (when -
- - 117     (and (coll? p) (= :fncall (first p)) (= :mvar (first (second p)))) -
- - 118      (make-cons-cell -
- - 119       (generate (second p) context) -
- - 120       (generate (nth p 2) context)))) -
- - 121   -
- - 122   -
- - 123  (defn gen-dot-terminated-list -
- - 124    "Generate a list, which may be dot-terminated, from this partial parse tree -
- - 125    'p'. Note that the function acts recursively and progressively decapitates -
- - 126    its argument, so that the argument will not always be a valid parse tree." -
- - 127    [p] -
- - 128    (cond -
- - 129      (empty? p) -
- - 130      NIL -
- - 131      (and (coll? (first p)) (= :dot-terminal (first (first p)))) -
- - 132      (let [dt (first p)] -
- - 133        (make-cons-cell -
- - 134         (generate (nth dt 1)) -
- - 135         (generate (nth dt 2)))) -
- - 136      :else -
- - 137      (make-cons-cell -
- - 138       (generate (first p)) -
- - 139       (gen-dot-terminated-list (rest p))))) -
- - 140   -
- - 141  ;; null[x] = [x = NIL -> T; T -> F] -
- - 142  ;; [:defn  -
- - 143  ;;  [:mexpr [:fncall [:mvar "null"] [:bindings [:args [:mexpr [:mvar "x"]]]]]]  -
- - 144  ;;  "="  -
- - 145  ;;  [:mexpr [:cond  -
- - 146  ;;           [:cond-clause [:mexpr [:iexpr [:lhs [:mexpr [:mvar "x"]]] [:iop "="] [:rhs [:mexpr [:mconst "NIL"]]]]] [:mexpr [:mconst "T"]]]  -
- - 147  ;;           [:cond-clause [:mexpr [:mconst "T"]] [:mexpr [:mconst "F"]]]]]] -
- - 148   -
- - 149  (defn generate-defn -
- - 150    [tree context] -
- - 151    (if (= :mexpr (first tree)) -
- - 152      (generate-defn (second tree) context) -
- - 153      (make-beowulf-list -
- - 154       (list 'PUT -
- - 155             (list 'QUOTE (generate (-> tree second second second) context)) -
- - 156             (list 'QUOTE 'EXPR) -
- - 157             (list 'QUOTE -
- - 158                   (cons 'LAMBDA -
- - 159                         (list (generate (nth (-> tree second second) 2) context) -
- - 160                               (generate (nth tree 3) context)))))))) -
- - 161   -
- - 162  (defn gen-iexpr -
- - 163    [tree context] -
- - 164    (let [bundle (reduce #(assoc %1 (first %2) %2) -
- - 165                         {} -
- - 166                         (rest tree))] -
- - 167      (list (generate (:iop bundle) context) -
- - 168            (generate (:lhs bundle) context) -
- - 169            (generate (:rhs bundle) context)))) -
- - 170   -
- - 171  (defn generate-set -
- - 172    "Actually not sure what the mexpr representation of set looks like" -
- - 173    [tree context] -
- - 174    (throw (ex-info "Not Yet Implemented" {:feature "generate-set"}))) -
- - 175   -
- - 176  (defn generate-assign -
- - 177    "Generate an assignment statement based on this `tree`. If the thing  -
- - 178     being assigned to is a function signature, then we have to do something  -
- - 179     different to if it's an atom." -
- - 180    [tree context] -
- - 181    (case (first (second tree)) -
- - 182      :fncall (generate-defn tree context) -
- - 183      :mexpr (map #(generate % context) (rest (second tree))) -
- - 184      (:mvar :atom) (generate-set tree context))) -
- - 185   -
- - 186  (defn strip-leading-zeros -
- - 187    "`read-string` interprets strings with leading zeros as octal; strip -
- - 188    any from this string `s`. If what's left is empty (i.e. there were -
- - 189    only zeros, return `\"0\"`." -
- - 190    ([s] -
- - 191     (strip-leading-zeros s "")) -
- - 192    ([s prefix] -
- - 193     (if -
- - 194      (empty? s) "0" -
- - 195      (case (first s) -
- - 196        (\+ \-) (strip-leading-zeros (subs s 1) (str (first s) prefix)) -
- - 197        "0" (strip-leading-zeros (subs s 1) prefix) -
- - 198        (str prefix s))))) -
- - 199   -
- - 200  (defn generate -
- - 201    "Generate lisp structure from this parse tree `p`. It is assumed that -
- - 202    `p` has been simplified." -
- - 203    ([p] -
- - 204     (generate p :expr)) -
- - 205    ([p context] -
- - 206     (try -
- - 207       (expand-macros -
- - 208        (if -
- - 209         (coll? p) -
- - 210          (case (first p) -
- - 211            :λ "LAMBDA" -
- - 212            :λexpr (make-cons-cell -
- - 213                    (generate (nth p 1) context) -
- - 214                    (make-cons-cell (generate (nth p 2) context) -
- - 215                                    (generate (nth p 3) context))) -
- - 216            :args (make-beowulf-list (map #(generate % context) (rest p))) -
- - 217            :atom (symbol (second p)) -
- - 218            :bindings (generate (second p) context) -
- - 219            :body (make-beowulf-list (map #(generate % context) (rest p))) -
- - 220            (:coefficient :exponent) (generate (second p) context) -
- - 221            :cond (gen-cond p (if (= context :mexpr) :cond-mexpr context)) -
- - 222            :cond-clause (gen-cond-clause p context) -
- - 223            :decimal (read-string (apply str (map second (rest p)))) -
- - 224            :defn (generate-defn p context) -
- - 225            :dotted-pair (make-cons-cell -
- - 226                          (generate (nth p 1) context) -
- - 227                          (generate (nth p 2) context)) -
- - 228            :fncall (gen-fn-call p context) -
- - 229            :iexpr (gen-iexpr p context) -
- - 230            :integer (read-string (strip-leading-zeros (second p))) -
- - 231            :iop (case (second p) -
- - 232                   "/" 'DIFFERENCE -
- - 233                   "=" 'EQUAL -
- - 234                   ">" 'GREATERP -
- - 235                   "<" 'LESSP -
- - 236                   "+" 'PLUS -
- - 237                   "*" 'TIMES -
- - 238                  ;; else -
- - 239                   (throw (ex-info "Unrecognised infix operator symbol" -
- - 240                                   {:phase :generate -
- - 241                                    :fragment p}))) -
- - 242            :list (gen-dot-terminated-list (rest p)) -
- - 243            (:lhs :rhs) (generate (second p) context) -
- - 244            :mexpr (generate (second p) (if (= context :cond-mexpr) context :mexpr)) -
- - 245            :mconst (if (= context :cond-mexpr) -
- - 246                      (case (second p) -
- - 247                        ("T" "F" "NIL") (symbol (second p)) -
- - 248                        ;; else -
- - 249                        (list 'QUOTE (symbol (second p)))) -
- - 250                      ;; else -
- - 251                      (list 'QUOTE (symbol (second p)))) -
- - 252            :mvar (symbol (upper-case (second p))) -
- - 253            :number (generate (second p) context) -
- - 254            :octal (let [n (read-string (strip-leading-zeros (second p) "0")) -
- - 255                         scale (generate (nth p 3) context)] -
- - 256                     (* n (expt 8 scale))) -
- - 257   -
- - 258        ;; the quote read macro (which probably didn't exist in Lisp 1.5, but...) -
- - 259            :quoted-expr (make-beowulf-list (list 'QUOTE (generate (second p) context))) -
- - 260            :scale-factor (if -
- - 261                           (empty? (second p)) 0 -
- - 262                           (read-string (strip-leading-zeros (second p)))) -
- - 263            :scientific (let [n (generate (second p) context) -
- - 264                              exponent (generate (nth p 3) context)] -
- - 265                          (* n (expt 10 exponent))) -
- - 266            :sexpr (generate (second p) :sexpr) -
- - 267            :subr (symbol (second p)) -
- - 268   -
- - 269        ;; default -
- - 270            (throw (ex-info (str "Unrecognised head: " (first p)) -
- - 271                            {:generating p}))) -
- - 272          p)) -
- - 273       (catch Throwable any -
- - 274         (throw (ex-info "Could not generate" -
- - 275                         {:generating p} -
- - 276                         any)))))) -
- - diff --git a/docs/cloverage/beowulf/reader/macros.clj.html b/docs/cloverage/beowulf/reader/macros.clj.html deleted file mode 100644 index 8a44ffc..0000000 --- a/docs/cloverage/beowulf/reader/macros.clj.html +++ /dev/null @@ -1,212 +0,0 @@ - - - - beowulf/reader/macros.clj - - - - 001  (ns beowulf.reader.macros -
- - 002    "Can I implement reader macros? let's see! -
- - 003      -
- - 004     We don't need (at least, in the Clojure reader) to rewrite forms like -
- - 005     `'FOO`, because that's handled by the parser. But we do need to rewrite -
- - 006     things which don't evaluate their arguments, like `SETQ`, because (unless -
- - 007     LABEL does it, which I'm not yet sure of) we're not yet able to implement -
- - 008     things which don't evaluate arguments. -
- - 009   -
- - 010     TODO: at this stage, the following should probably also be read macros: -
- - 011     DEFINE" -
- - 012    (:require [beowulf.cons-cell :refer [make-beowulf-list]] -
- - 013              [beowulf.host :refer [CONS LIST]] -
- - 014              [clojure.string :refer [join]])) -
- - 015   -
- - 016  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 017  ;;; -
- - 018  ;;; We don't need (at least, in the Clojure reader) to rewrite forms like -
- - 019  ;;; "'FOO", because that's handled by the parser. But we do need to rewrite -
- - 020  ;;; things which don't evaluate their arguments, like `SETQ`, because (unless -
- - 021  ;;; LABEL does it, which I'm not yet sure of) we're not yet able to implement -
- - 022  ;;; things which don't evaluate arguments. -
- - 023  ;;; -
- - 024  ;;; TODO: at this stage, the following should probably also be read macros: -
- - 025  ;;; DEFINE -
- - 026  ;;; -
- - 027  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 028  ;;; -
- - 029  ;;; Copyright (C) 2022-2023 Simon Brooke -
- - 030  ;;; -
- - 031  ;;; This program is free software; you can redistribute it and/or -
- - 032  ;;; modify it under the terms of the GNU General Public License -
- - 033  ;;; as published by the Free Software Foundation; either version 2 -
- - 034  ;;; of the License, or (at your option) any later version. -
- - 035  ;;;  -
- - 036  ;;; This program is distributed in the hope that it will be useful, -
- - 037  ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -
- - 038  ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -
- - 039  ;;; GNU General Public License for more details. -
- - 040  ;;;  -
- - 041  ;;; You should have received a copy of the GNU General Public License -
- - 042  ;;; along with this program; if not, write to the Free Software -
- - 043  ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. -
- - 044  ;;; -
- - 045  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 046   -
- - 047  (def ^:dynamic *readmacros* -
- - 048    {:car {'DEFUN (fn [f] -
- - 049                    (LIST 'SET (LIST 'QUOTE (second f)) -
- - 050                          (LIST 'QUOTE (CONS 'LAMBDA (rest (rest f)))))) -
- - 051           'SETQ (fn [f] (LIST 'SET (LIST 'QUOTE (second f)) (nth f 2)))}}) -
- - 052   -
- - 053  (defn expand-macros -
- - 054    [form] -
- - 055    (try -
- - 056      (if-let [car (when (and (coll? form) (symbol? (first form)))  -
- - 057                     (first form))] -
- - 058        (if-let [macro (-> *readmacros* :car car)] -
- - 059          (make-beowulf-list (apply macro (list form))) -
- - 060          form) -
- - 061        form) -
- - 062      (catch Exception any -
- - 063        (println (join "\n" -
- - 064                       ["# ERROR while expanding macro:" -
- - 065                        (str "# Form: " form) -
- - 066                        (str "# Error class: " (.getName (.getClass any))) -
- - 067                        (str "# Message: " (.getMessage any))])) -
- - 068        form))) -
- - diff --git a/docs/cloverage/beowulf/reader/parser.clj.html b/docs/cloverage/beowulf/reader/parser.clj.html deleted file mode 100644 index 0e8427d..0000000 --- a/docs/cloverage/beowulf/reader/parser.clj.html +++ /dev/null @@ -1,368 +0,0 @@ - - - - beowulf/reader/parser.clj - - - - 001  (ns beowulf.reader.parser -
- - 002    "The actual parser, supporting both S-expression and M-expression syntax." -
- - 003    (:require [instaparse.core :as i])) -
- - 004   -
- - 005  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 006  ;;; -
- - 007  ;;; Copyright (C) 2022-2023 Simon Brooke -
- - 008  ;;; -
- - 009  ;;; This program is free software; you can redistribute it and/or -
- - 010  ;;; modify it under the terms of the GNU General Public License -
- - 011  ;;; as published by the Free Software Foundation; either version 2 -
- - 012  ;;; of the License, or (at your option) any later version. -
- - 013  ;;;  -
- - 014  ;;; This program is distributed in the hope that it will be useful, -
- - 015  ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -
- - 016  ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -
- - 017  ;;; GNU General Public License for more details. -
- - 018  ;;;  -
- - 019  ;;; You should have received a copy of the GNU General Public License -
- - 020  ;;; along with this program; if not, write to the Free Software -
- - 021  ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. -
- - 022  ;;; -
- - 023  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 024   -
- - 025  (def parse -
- - 026    "Parse a string presented as argument into a parse tree which can then -
- - 027    be operated upon further." -
- - 028    (i/parser -
- - 029     (str -
- - 030      ;; we tolerate whitespace and comments around legitimate input -
- - 031      "raw := expr | opt-comment expr opt-comment;" -
- - 032      ;; top level: we accept mexprs as well as sexprs. -
- - 033      "expr := mexpr | sexpr ;" -
- - 034   -
- - 035      ;; comments. I'm pretty confident Lisp 1.5 did NOT have these. -
- - 036      "comment := opt-space <';;'> opt-space #'[^\\n\\r]*';" -
- - 037   -
- - 038      ;; there's a notation comprising a left brace followed by mexprs -
- - 039      ;; followed by a right brace which doesn't seem to be documented  -
- - 040      ;; but I think must represent assembly code(?) -
- - 041   -
- - 042      ;; "assembly := lbrace exprs rbrace;" -
- - 043   -
- - 044      ;; mexprs. I'm pretty clear that Lisp 1.5 could never read these, -
- - 045      ;; but it's a convenience. -
- - 046   -
- - 047      ;; TODO: this works for now but in fact the Programmer's Manual -
- - 048      ;; gives a much simpler formulation of M-expression grammar on -
- - 049      ;; page 9, and of the S-expression grammar on page 8. It would -
- - 050      ;; be worth going back and redoing this from the book. -
- - 051   -
- - 052      "exprs := expr | exprs;" -
- - 053      "mexpr := λexpr | fncall | defn | cond | mvar | mconst | iexpr | number | mexpr comment; -
- - 054        λexpr := λ lsqb bindings semi-colon opt-space body opt-space rsqb; -
- - 055        λ := 'λ' | 'lambda'; -
- - 056        bindings := lsqb args rsqb | lsqb rsqb; -
- - 057        body := (opt-space mexpr semi-colon)* opt-space mexpr; -
- - 058        fncall := fn-name bindings; -
- - 059        lsqb := '['; -
- - 060        rsqb := ']'; -
- - 061        lbrace := '{'; -
- - 062        rbrace := '}'; -
- - 063        defn := mexpr opt-space '=' opt-space mexpr; -
- - 064        cond := lsqb (opt-space cond-clause semi-colon opt-space)* cond-clause rsqb; -
- - 065        cond-clause := mexpr opt-space arrow opt-space mexpr opt-space; -
- - 066        arrow := '->'; -
- - 067        args := arg | (opt-space arg semi-colon opt-space)* opt-space arg opt-space; -
- - 068        arg := mexpr; -
- - 069        fn-name := mvar; -
- - 070        mvar := #'[a-z][a-z0-9]*'; -
- - 071        mconst := #'[A-Z][A-Z0-9]*'; -
- - 072        semi-colon := ';';" -
- - 073   -
- - 074      ;; Infix operators appear in mexprs, e.g. on page 7. Ooops! -
- - 075      ;; I do not know what infix operators are considered legal. -
- - 076      ;; In particular I do not know what symbol was used for -
- - 077      ;; multiply -
- - 078      "iexpr := iexp iop iexp; -
- - 079       iexp := mexpr | number | opt-space iexp opt-space; -
- - 080      iop := '>' | '<' | '+' | '-' | '*' '/' | '=' ;" -
- - 081   -
- - 082      ;; comments. I'm pretty confident Lisp 1.5 did NOT have these. -
- - 083      "opt-comment := opt-space | comment;" -
- - 084      "comment := opt-space <';;'> #'[^\\n\\r]*' opt-space;" -
- - 085   -
- - 086      ;; sexprs. Note it's not clear to me whether Lisp 1.5 had the quote macro, -
- - 087      ;; but I've included it on the basis that it can do little harm. -
- - 088      "sexpr := quoted-expr | atom | number | subr | dotted-pair | list | sexpr comment; -
- - 089        list := lpar sexpr rpar | lpar (sexpr sep)* rpar | lpar (sexpr sep)* dot-terminal | lbrace exprs rbrace; -
- - 090        list := lpar opt-space sexpr rpar | lpar opt-space (sexpr sep)* rpar | lpar opt-space (sexpr sep)* dot-terminal; -
- - 091        dotted-pair := lpar dot-terminal ; -
- - 092        dot := '.'; -
- - 093        lpar := '('; -
- - 094        rpar := ')'; -
- - 095        quoted-expr := quote sexpr; -
- - 096        quote := '\\''; -
- - 097        dot-terminal := sexpr space dot space sexpr rpar; -
- - 098        space := #'\\p{javaWhitespace}+'; -
- - 099        opt-space := #'\\p{javaWhitespace}*'; -
- - 100        sep := ',' | opt-space; -
- - 101        atom := #'[A-Z][A-Z0-9]*';" -
- - 102   -
- - 103      ;; we need a way of representing Clojure functions on the object list; -
- - 104      ;; subr objects aren't expected to be normally entered on the REPL, but -
- - 105      ;; must be on the object list or functions to which functions are passed -
- - 106      ;; won't be able to access them. -
- - 107      "subr := #'[a-z][a-z.]*/[A-Za-z][A-Za-z0-9]*';" -
- - 108   -
- - 109      ;; Lisp 1.5 supported octal as well as decimal and scientific notation -
- - 110      "number := integer | decimal | scientific | octal; -
- - 111        integer := #'-?[0-9]+'; -
- - 112        decimal := integer dot integer; -
- - 113        scientific := coefficient e exponent; -
- - 114        coefficient := decimal | integer; -
- - 115        exponent := integer; -
- - 116        e := 'E'; -
- - 117        octal := #'[+-]?[0-7]+{1,12}' q scale-factor; -
- - 118        q := 'Q'; -
- - 119        scale-factor := #'[0-9]*'"))) -
- - 120   -
- - diff --git a/docs/cloverage/beowulf/reader/simplify.clj.html b/docs/cloverage/beowulf/reader/simplify.clj.html deleted file mode 100644 index 8d50e4d..0000000 --- a/docs/cloverage/beowulf/reader/simplify.clj.html +++ /dev/null @@ -1,401 +0,0 @@ - - - - beowulf/reader/simplify.clj - - - - 001  (ns beowulf.reader.simplify -
- - 002    "Simplify parse trees. Be aware that this is very tightly coupled -
- - 003     with the parser." -
- - 004    (:require [beowulf.oblist :refer [*options*]] -
- - 005              [instaparse.failure :as f]) -
- - 006    (:import [instaparse.gll Failure])) -
- - 007   -
- - 008  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 009  ;;; -
- - 010  ;;; Copyright (C) 2022-2023 Simon Brooke -
- - 011  ;;; -
- - 012  ;;; This program is free software; you can redistribute it and/or -
- - 013  ;;; modify it under the terms of the GNU General Public License -
- - 014  ;;; as published by the Free Software Foundation; either version 2 -
- - 015  ;;; of the License, or (at your option) any later version. -
- - 016  ;;;  -
- - 017  ;;; This program is distributed in the hope that it will be useful, -
- - 018  ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -
- - 019  ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -
- - 020  ;;; GNU General Public License for more details. -
- - 021  ;;;  -
- - 022  ;;; You should have received a copy of the GNU General Public License -
- - 023  ;;; along with this program; if not, write to the Free Software -
- - 024  ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. -
- - 025  ;;; -
- - 026  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
- - 027   -
- - 028  (declare simplify-tree) -
- - 029   -
- - 030  (defn remove-optional-space -
- - 031    [tree] -
- - 032    (if (vector? tree) -
- - 033      (if (= :opt-space (first tree)) -
- - 034        nil -
- - 035        (let [v (remove nil? -
- - 036                        (map remove-optional-space tree))] -
- - 037          (if (seq v) -
- - 038            (apply vector v) -
- - 039            v))) -
- - 040      tree)) -
- - 041   -
- - 042  (defn remove-nesting -
- - 043    [tree context] -
- - 044    (let [tree' (remove-optional-space tree)] -
- - 045      (if-let [key (when (and (vector? tree')  -
- - 046                              (keyword? (first tree')))  -
- - 047                     (first tree'))] -
- - 048        (loop [r tree'] -
- - 049          (if (and r (vector? r) (keyword? (first r))) -
- - 050            (if (= (first r) key) -
- - 051              (recur (simplify-tree (second r) context)) -
- - 052              r) -
- - 053            r)) -
- - 054        tree'))) -
- - 055   -
- - 056  (defn simplify-tree -
- - 057    "Simplify this parse tree `p`. If `p` is an instaparse failure object, throw -
- - 058     an `ex-info`, with `p` as the value of its `:failure` key. -
- - 059      -
- - 060     **NOTE THAT** it is assumed that `remove-optional-space` has been run on the -
- - 061     parse tree **BEFORE** it is passed to `simplify-tree`." -
- - 062    ([p] -
- - 063     (if -
- - 064      (instance? Failure p) -
- - 065       (throw (ex-info -
- - 066               (str "Ic ne behæfd: " (f/pprint-failure p)) -
- - 067               {:cause :parse-failure -
- - 068                :phase   :simplify -
- - 069                :failure p})) -
- - 070       (simplify-tree p :expr))) -
- - 071    ([p context] -
- - 072     (cond -
- - 073       (string? p) p -
- - 074       (coll? p) (apply -
- - 075                  vector -
- - 076                  (remove -
- - 077                   #(when (coll? %) (empty? %)) -
- - 078                   (case (first p) -
- - 079                     (:λexpr -
- - 080                      :args :bindings :body :cond :cond-clause :defn :dot-terminal  -
- - 081                      :fncall :lhs :quoted-expr :rhs ) (map #(simplify-tree % context) p) -
- - 082                     (:arg :expr :coefficient :fn-name :number) (simplify-tree (second p) context) -
- - 083                     (:arrow :dot :e :lpar :lsqb  :opt-comment :opt-space :q :quote :rpar :rsqb -
- - 084                             :semi-colon :sep :space) nil -
- - 085                     :atom (if -
- - 086                            (= context :mexpr) -
- - 087                             [:quoted-expr p] -
- - 088                             p) -
- - 089                     :comment (when -
- - 090                               (:strict *options*) -
- - 091                                (throw -
- - 092                                 (ex-info "Cannot parse comments in strict mode" -
- - 093                                          {:cause :strict}))) -
- - 094                     (:decimal :integer :mconst :octal :scientific) p -
- - 095                     :dotted-pair (if -
- - 096                                   (= context :mexpr) -
- - 097                                    [:fncall -
- - 098                                     [:mvar "cons"] -
- - 099                                     [:args -
- - 100                                      (simplify-tree (nth p 1) context) -
- - 101                                      (simplify-tree (nth p 2) context)]] -
- - 102                                    (map #(simplify-tree % context) p)) -
- - 103                     :iexp (simplify-tree (second p) context) -
- - 104                     :iexpr [:iexpr -
- - 105                             [:lhs (simplify-tree (second p) context)] -
- - 106                             (simplify-tree (nth p 2) context) ;; really should be the operator -
- - 107                             [:rhs (simplify-tree (nth p 3) context)]] -
- - 108                     :mexpr (if -
- - 109                             (:strict *options*) -
- - 110                              (throw -
- - 111                               (ex-info "Cannot parse meta expressions in strict mode" -
- - 112                                        {:cause :strict})) -
- - 113                              [:mexpr (simplify-tree (second p) :mexpr)]) -
- - 114                     :list (if -
- - 115                            (= context :mexpr) -
- - 116                             [:fncall -
- - 117                              [:mvar "list"] -
- - 118                              [:args (apply vector (map simplify-tree (rest p)))]] -
- - 119                             (map #(simplify-tree % context) p)) -
- - 120                     :raw (first (remove empty? (map simplify-tree (rest p)))) -
- - 121                     :sexpr [:sexpr (simplify-tree (second p) :sexpr)] -
- - 122            ;;default -
- - 123                     p))) -
- - 124       :else p))) -
- - 125   -
- - 126  (defn simplify -
- - 127    "Simplify this parse tree `p`. If `p` is an instaparse failure object, throw -
- - 128     an `ex-info`, with `p` as the value of its `:failure` key. Calls  -
- - 129     `remove-optional-space` before processing." -
- - 130    [p] -
- - 131    (simplify-tree (remove-optional-space p))) -
- - diff --git a/docs/cloverage/index.html b/docs/cloverage/index.html index 8f8236c..b064548 100644 --- a/docs/cloverage/index.html +++ b/docs/cloverage/index.html @@ -16,225 +16,88 @@ beowulf.bootstrap
624
352
-63.93 % + style="width:60.47808764940239%; + float:left;"> 759
496
+60.48 %
138
19
75
-67.67 % -42233232 + style="width:47.92626728110599%; + float:left;"> 104
42
71
+67.28 % +41446217 beowulf.cons-cell
348
133
-72.35 % + style="width:56.82819383259912%; + float:left;"> 129
98
+56.83 %
109
9
27
-81.38 % -27423145 + style="width:57.35294117647059%; + float:left;"> 39
3
26
+61.76 % +1561568 beowulf.core
198
87
-69.47 % + style="width:90.9090909090909%; + float:left;"> 170
17
+90.91 %
50
4
15
-78.26 % -132669 + style="width:87.75510204081633%; + float:left;"> 43
1
5
+89.80 % +80349 beowulf.host
1027
1374
-42.77 % -
137
37
81
-68.24 % -57166255 - - - beowulf.interop
142
104
-57.72 % -
31
6
29
-56.06 % -1291166 - - - beowulf.io
142
181
-43.96 % -
33
6
32
-54.93 % -1711271 - - - beowulf.manual
1721
73
-95.93 % -
298
17
-94.60 % -7694315 - - - beowulf.oblist
9
+ float:left;"> 1 100.00 %
6
+ float:left;"> 1 100.00 % -4556 +511 beowulf.read
87
89
-49.43 % + style="width:81.8941504178273%; + float:left;"> 588
130
+81.89 %
21
3
15
-61.54 % -108939 - - - beowulf.reader.char-reader
1
-100.00 % -
1
-100.00 % -7541 - - - beowulf.reader.generate
492
213
-69.79 % -
85
93
10
31
-75.40 % -27621126 - - - beowulf.reader.macros
85
21
-80.19 % -
14
6
-70.00 % -68420 - - - beowulf.reader.parser
17
-100.00 % -
4
-100.00 % -120144 - - - beowulf.reader.simplify
255
190
-57.30 % -
40
3
38
-53.09 % -131681 + style="width:18.253968253968253%; + float:left;"> 23 +81.75 % +31531126 Totals: -64.63 % +68.97 % -74.41 % +72.89 % diff --git a/docs/codox/beowulf.bootstrap.html b/docs/codox/beowulf.bootstrap.html index 8301c99..068508a 100644 --- a/docs/codox/beowulf.bootstrap.html +++ b/docs/codox/beowulf.bootstrap.html @@ -1,17 +1,13 @@ -beowulf.bootstrap documentation

beowulf.bootstrap

Lisp as defined in Chapter 1 (pages 1-14) of the Lisp 1.5 Programmer's Manual; that is to say, a very simple Lisp language, which should, I believe, be sufficient in conjunction with the functions provided by beowulf.host, be sufficient to bootstrap the full Lisp 1.5 interpreter..

+beowulf.bootstrap documentation

beowulf.bootstrap

Lisp as defined in Chapter 1 (pages 1-14) of the Lisp 1.5 Programmer's Manual; that is to say, a very simple Lisp language, which should, I believe, be sufficient in conjunction with the functions provided by beowulf.host, be sufficient to bootstrap the full Lisp 1.5 interpreter..

The convention is adopted that functions in this file with names in ALLUPPERCASE are Lisp 1.5 functions (although written in Clojure) and that therefore all arguments must be numbers, symbols or beowulf.cons_cell.ConsCell objects.

APPLY

(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.

EVAL

(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. 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.

find-target

TODO: write docs

PROG

(PROG program env depth)

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 PROGs 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 A3except 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.

prog-eval

(prog-eval expr vars env depth)

Like EVAL, q.v., except handling symbols, and expressions starting GO, RETURN, SET and SETQ specially.

try-resolve-subroutine

(try-resolve-subroutine subr args)

Attempt to resolve this subr with these args.

\ No newline at end of file +

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.

CAAAAR

macro

(CAAAAR x)

TODO: write docs

CAAADR

macro

(CAAADR x)

TODO: write docs

CAAAR

macro

(CAAAR x)

TODO: write docs

CAADAR

macro

(CAADAR x)

TODO: write docs

CAADDR

macro

(CAADDR x)

TODO: write docs

CAADR

macro

(CAADR x)

TODO: write docs

CAAR

macro

(CAAR x)

TODO: write docs

CADAAR

macro

(CADAAR x)

TODO: write docs

CADADR

macro

(CADADR x)

TODO: write docs

CADAR

macro

(CADAR x)

TODO: write docs

CADDAR

macro

(CADDAR x)

TODO: write docs

CADDDR

macro

(CADDDR x)

TODO: write docs

CADDR

macro

(CADDR x)

TODO: write docs

CADR

macro

(CADR x)

TODO: write docs

CDAAAR

macro

(CDAAAR x)

TODO: write docs

CDAADR

macro

(CDAADR x)

TODO: write docs

CDAAR

macro

(CDAAR x)

TODO: write docs

CDADAR

macro

(CDADAR x)

TODO: write docs

CDADDR

macro

(CDADDR x)

TODO: write docs

CDADR

macro

(CDADR x)

TODO: write docs

CDAR

macro

(CDAR x)

TODO: write docs

CDDAAR

macro

(CDDAAR x)

TODO: write docs

CDDADR

macro

(CDDADR x)

TODO: write docs

CDDAR

macro

(CDDAR x)

TODO: write docs

CDDDAR

macro

(CDDDAR x)

TODO: write docs

CDDDDR

macro

(CDDDDR x)

TODO: write docs

CDDDR

macro

(CDDDR x)

TODO: write docs

CDDR

macro

(CDDR x)

TODO: write docs

EVAL

(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.

INTEROP

(INTEROP fn-symbol args)

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. +
  3. a sequence (list) of symbols forming a qualified path name bound to a function.
  4. +
+

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.

interop-interpret-q-name

(interop-interpret-q-name l)

For interoperation with Clojure, it will often be necessary to pass qualified names that are not representable in Lisp 1.5. This function takes a sequence in the form (PART PART PART... NAME) and returns a symbol in the form PART.PART.PART/NAME. This symbol will then be tried in both that form and lower-cased. Names with hyphens or underscores cannot be represented with this scheme.

QUOTE

macro

(QUOTE f)

Quote, but in upper case for LISP 1.5

to-beowulf

(to-beowulf o)

Return a beowulf-native representation of the Clojure object o. Numbers and symbols are unaffected. Collections have to be converted; strings must be converted to symbols.

to-clojure

(to-clojure l)

If l is a beowulf.cons_cell.ConsCell, return a Clojure list having the same members in the same order.

uaf

(uaf l path)

Universal access function; l is expected to be an arbitrary LISP list, path a (clojure) list of the characters a and d. Intended to make declaring all those fiddly #'c[ad]+r' functions a bit easier

\ No newline at end of file diff --git a/docs/codox/beowulf.cons-cell.html b/docs/codox/beowulf.cons-cell.html index 6e2b315..26fa55a 100644 --- a/docs/codox/beowulf.cons-cell.html +++ b/docs/codox/beowulf.cons-cell.html @@ -1,3 +1,3 @@ -beowulf.cons-cell documentation

beowulf.cons-cell

The fundamental cons cell on which all Lisp structures are built. Lisp 1.5 lists do not necessarily have a sequence as their CDR, and must have both CAR and CDR mutable, so cannot be implemented on top of Clojure lists.

cons-cell?

(cons-cell? o)

Is this object o a beowulf cons-cell?

F

The canonical false value - different from NIL, which is not canonically false in Lisp 1.5.

make-beowulf-list

(make-beowulf-list x)

Construct a linked list of cons cells with the same content as the sequence x.

make-cons-cell

(make-cons-cell car cdr)

Construct a new instance of cons cell with this car and cdr.

MutableSequence

protocol

Like a sequence, but mutable.

members

getCar

(getCar this)

Return the first element of this sequence.

getCdr

(getCdr this)

like more, q.v., but returns List NIL not Clojure nil when empty.

getUid

(getUid this)

Returns a unique identifier for this object

rplaca

(rplaca this value)

replace the first element of this sequence with this value

rplacd

(rplacd this value)

replace the rest (but-first; cdr) of this sequence with this value

pretty-print

(pretty-print cell)(pretty-print cell width level)

This isn’t the world’s best pretty printer but it sort of works.

T

The canonical true value.

\ No newline at end of file +beowulf.cons-cell documentation

beowulf.cons-cell

The fundamental cons cell on which all Lisp structures are built. Lisp 1.5 lists do not necessarily have a sequence as their CDR, and must have both CAR and CDR mutable, so cannot be implemented on top of Clojure lists.

cons-cell?

(cons-cell? o)

Is this object o a beowulf cons-cell?

F

The canonical false value - different from NIL, which is not canonically false in Lisp 1.5.

make-beowulf-list

(make-beowulf-list x)

Construct a linked list of cons cells with the same content as the sequence x.

make-cons-cell

(make-cons-cell car cdr)

Construct a new instance of cons cell with this car and cdr.

MutableSequence

protocol

Like a sequence, but mutable.

members

getCar

(getCar this)

Return the first element of this sequence.

getCdr

(getCdr this)

like more, q.v., but returns List NIL not Clojure nil when empty.

getUid

(getUid this)

Returns a unique identifier for this object

rplaca

(rplaca this value)

replace the first element of this sequence with this value

rplacd

(rplacd this value)

replace the rest (but-first; cdr) of this sequence with this value

pretty-print

(pretty-print cell)(pretty-print cell width level)

This isn’t the world’s best pretty printer but it sort of works.

T

The canonical true value.

\ No newline at end of file diff --git a/docs/codox/beowulf.core.html b/docs/codox/beowulf.core.html index 8b8b2ef..660d5f5 100644 --- a/docs/codox/beowulf.core.html +++ b/docs/codox/beowulf.core.html @@ -1,3 +1,3 @@ -beowulf.core documentation

beowulf.core

Essentially, the -main function and the bootstrap read-eval-print loop.

-main

(-main & opts)

Parse options, print the banner, read the init file if any, and enter the read/eval/print loop.

cli-options

TODO: write docs

repl

(repl prompt)

Read/eval/print loop.

stop-word

The word which, if submitted an an input line, will cause Beowulf to quit. Question: should this be forlǣte?

\ No newline at end of file +beowulf.core documentation

beowulf.core

Essentially, the -main function and the bootstrap read-eval-print loop.

-main

(-main & opts)

Parse options, print the banner, read the init file if any, and enter the read/eval/print loop.

cli-options

TODO: write docs

repl

(repl prompt)

Read/eval/print loop.

stop-word

TODO: write docs

\ No newline at end of file diff --git a/docs/codox/beowulf.gendoc.html b/docs/codox/beowulf.gendoc.html index 763e8ab..208efe6 100644 --- a/docs/codox/beowulf.gendoc.html +++ b/docs/codox/beowulf.gendoc.html @@ -1,4 +1,4 @@ -beowulf.gendoc documentation

beowulf.gendoc

Generate table of documentation of Lisp symbols and functions.

-

NOTE: this is very hacky. You almost certainly do not want to use this!

find-documentation

(find-documentation entry)

Find appropriate documentation for this entry from the oblist.

gen-doc-table

(gen-doc-table)

TODO: write docs

gen-index

(gen-index)(gen-index url destination)

TODO: write docs

host-functions

Functions which we can infer are written in Clojure. We need to collect these at run-time, not compile time, hence memoised function, not variable.

infer-implementation

(infer-implementation entry)

TODO: write docs

infer-signature

(infer-signature entry)

Infer the signature of the function value of this oblist entry, if any.

infer-type

(infer-type entry)

Try to work out what this entry from the oblist actually represents.

open-doc

(open-doc symbol)

Open the documentation page for this symbol, if known, in the default web browser.

\ No newline at end of file +beowulf.gendoc documentation

beowulf.gendoc

Generate table of documentation of Lisp symbols and functions.

+

NOTE: this is very hacky. You almost certainly do not want to use this!

find-documentation

(find-documentation entry)

Find appropriate documentation for this entry from the oblist.

gen-doc-table

(gen-doc-table)

TODO: write docs

gen-index

(gen-index)(gen-index url destination)

TODO: write docs

host-functions

Functions which we can infer are written in Clojure. We need to collect these at run-time, not compile time, hence memoised function, not variable.

infer-implementation

(infer-implementation entry)

TODO: write docs

infer-signature

(infer-signature entry)

Infer the signature of the function value of this oblist entry, if any.

infer-type

(infer-type entry)

Try to work out what this entry from the oblist actually represents.

open-doc

(open-doc symbol)

Open the documentation page for this symbol, if known, in the default web browser.

\ No newline at end of file diff --git a/docs/codox/beowulf.host.html b/docs/codox/beowulf.host.html index d6c6f6f..c22765d 100644 --- a/docs/codox/beowulf.host.html +++ b/docs/codox/beowulf.host.html @@ -1,19 +1,14 @@ -beowulf.host documentation

beowulf.host

provides Lisp 1.5 functions which can’t be (or can’t efficiently be) implemented in Lisp 1.5, which therefore need to be implemented in the host language, in this case Clojure.

ADD1

(ADD1 x)

TODO: write docs

AND

(AND & args)

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.

ASSOC

(ASSOC x a)

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.

+beowulf.host documentation

beowulf.host

provides Lisp 1.5 functions which can’t be (or can’t efficiently be) implemented in Lisp 1.5, which therefore need to be implemented in the host language, in this case Clojure.

ADD1

(ADD1 x)

TODO: write docs

AND

(AND & args)

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.

ASSOC

(ASSOC x a)

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

(ATOM x)

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.

ATOM?

macro

(ATOM? x)

The convention of returning F from predicates, rather than NIL, is going to tie me in knots. This is a variant of ATOM which returns NIL on failure.

CAAAAR

macro

(CAAAAR x)

TODO: write docs

CAAADR

macro

(CAAADR x)

TODO: write docs

CAAAR

macro

(CAAAR x)

TODO: write docs

CAADAR

macro

(CAADAR x)

TODO: write docs

CAADDR

macro

(CAADDR x)

TODO: write docs

CAADR

macro

(CAADR x)

TODO: write docs

CAAR

macro

(CAAR x)

TODO: write docs

CADAAR

macro

(CADAAR x)

TODO: write docs

CADADR

macro

(CADADR x)

TODO: write docs

CADAR

macro

(CADAR x)

TODO: write docs

CADDAR

macro

(CADDAR x)

TODO: write docs

CADDDR

macro

(CADDDR x)

TODO: write docs

CADDR

macro

(CADDR x)

TODO: write docs

CADR

macro

(CADR x)

TODO: write docs

CAR

(CAR x)

Return the item indicated by the first pointer of a pair. NIL is treated specially: the CAR of NIL is NIL.

CDAAAR

macro

(CDAAAR x)

TODO: write docs

CDAADR

macro

(CDAADR x)

TODO: write docs

CDAAR

macro

(CDAAR x)

TODO: write docs

CDADAR

macro

(CDADAR x)

TODO: write docs

CDADDR

macro

(CDADDR x)

TODO: write docs

CDADR

macro

(CDADR x)

TODO: write docs

CDAR

macro

(CDAR x)

TODO: write docs

CDDAAR

macro

(CDDAAR x)

TODO: write docs

CDDADR

macro

(CDDADR x)

TODO: write docs

CDDAR

macro

(CDDAR x)

TODO: write docs

CDDDAR

macro

(CDDDAR x)

TODO: write docs

CDDDDR

macro

(CDDDDR x)

TODO: write docs

CDDDR

macro

(CDDDR x)

TODO: write docs

CDDR

macro

(CDDR x)

TODO: write docs

CDR

(CDR x)

Return the item indicated by the second pointer of a pair. NIL is treated specially: the CDR of NIL is NIL.

CONS

(CONS car cdr)

Construct a new instance of cons cell with this car and cdr.

CONSP

(CONSP o)

Return T if object o is a cons cell, else F.

-

NOTE THAT this is an extension function, not available in strct mode. I believe that Lisp 1.5 did not have any mechanism for testing whether an argument was, or was not, a cons cell.

DEFINE

(DEFINE a-list)

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.

DEFLIST

(DEFLIST a-list indicator)

For each pair in this association list a-list, set the property with this indicator of the symbol which is the first element of the pair to the value which is the second element of the pair. See page 58 of the manual.

DIFFERENCE

(DIFFERENCE x y)

TODO: write docs

DOC

(DOC symbol)

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.

EQ

(EQ x y)

Returns T if and only if both x and y are bound to the same atom, else NIL.

EQUAL

(EQUAL x y)

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

ERROR

(ERROR & args)

Throw an error

FIXP

(FIXP x)

TODO: write docs

GENSYM

(GENSYM)

Generate a unique symbol.

GET

(GET symbol indicator)

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

(GREATERP x y)

TODO: write docs

lax?

(lax? symbol)

Are we in lax mode? If so. return true; is not, throw an exception with this symbol.

LESSP

(LESSP x y)

TODO: write docs

LIST

(LIST & args)

TODO: write docs

magic-marker

The unexplained magic number which marks the start of a property list.

NILP

macro

(NILP x)

Not part of LISP 1.5: T if o is NIL, else NIL.

NULL

macro

(NULL x)

Returns T if and only if the argument x is bound to NIL; else F.

NUMBERP

(NUMBERP x)

TODO: write docs

OBLIST

(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.

OR

(OR & args)

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.

PAIRLIS

(PAIRLIS x y a)

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.

+

NOTE THAT this function is overridden by an implementation in Lisp, but is currently still present for bootstrapping.

ATOM

(ATOM x)

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.

ATOM?

macro

(ATOM? x)

The convention of returning F from predicates, rather than NIL, is going to tie me in knots. This is a variant of ATOM which returns NIL on failure.

CAAAAR

macro

(CAAAAR x)

TODO: write docs

CAAADR

macro

(CAAADR x)

TODO: write docs

CAAAR

macro

(CAAAR x)

TODO: write docs

CAADAR

macro

(CAADAR x)

TODO: write docs

CAADDR

macro

(CAADDR x)

TODO: write docs

CAADR

macro

(CAADR x)

TODO: write docs

CAAR

macro

(CAAR x)

TODO: write docs

CADAAR

macro

(CADAAR x)

TODO: write docs

CADADR

macro

(CADADR x)

TODO: write docs

CADAR

macro

(CADAR x)

TODO: write docs

CADDAR

macro

(CADDAR x)

TODO: write docs

CADDDR

macro

(CADDDR x)

TODO: write docs

CADDR

macro

(CADDR x)

TODO: write docs

CADR

macro

(CADR x)

TODO: write docs

CAR

(CAR x)

Return the item indicated by the first pointer of a pair. NIL is treated specially: the CAR of NIL is NIL.

CDAAAR

macro

(CDAAAR x)

TODO: write docs

CDAADR

macro

(CDAADR x)

TODO: write docs

CDAAR

macro

(CDAAR x)

TODO: write docs

CDADAR

macro

(CDADAR x)

TODO: write docs

CDADDR

macro

(CDADDR x)

TODO: write docs

CDADR

macro

(CDADR x)

TODO: write docs

CDAR

macro

(CDAR x)

TODO: write docs

CDDAAR

macro

(CDDAAR x)

TODO: write docs

CDDADR

macro

(CDDADR x)

TODO: write docs

CDDAR

macro

(CDDAR x)

TODO: write docs

CDDDAR

macro

(CDDDAR x)

TODO: write docs

CDDDDR

macro

(CDDDDR x)

TODO: write docs

CDDDR

macro

(CDDDR x)

TODO: write docs

CDDR

macro

(CDDR x)

TODO: write docs

CDR

(CDR x)

Return the item indicated by the second pointer of a pair. NIL is treated specially: the CDR of NIL is NIL.

CONS

(CONS car cdr)

Construct a new instance of cons cell with this car and cdr.

CONSP

(CONSP o)

Return T if object o is a cons cell, else F.

+

NOTE THAT this is an extension function, not available in strct mode. I believe that Lisp 1.5 did not have any mechanism for testing whether an argument was, or was not, a cons cell.

DEFINE

(DEFINE args)

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

(DIFFERENCE x y)

TODO: write docs

DOC

(DOC symbol)

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.

EQ

(EQ x y)

Returns T if and only if both x and y are bound to the same atom, else NIL.

EQUAL

(EQUAL x y)

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

ERROR

(ERROR & args)

Throw an error

FIXP

(FIXP x)

TODO: write docs

GENSYM

(GENSYM)

Generate a unique symbol.

GREATERP

(GREATERP x y)

TODO: write docs

lax?

(lax? symbol)

Are we in lax mode? If so. return true; is not, throw an exception with this symbol.

LESSP

(LESSP x y)

TODO: write docs

LIST

(LIST & args)

TODO: write docs

NILP

macro

(NILP x)

Not part of LISP 1.5: T if o is NIL, else NIL.

NULL

macro

(NULL x)

Returns T if and only if the argument x is bound to NIL; else F.

NUMBERP

(NUMBERP x)

TODO: write docs

OBLIST

(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.

PAIRLIS

(PAIRLIS x y a)

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.

Eessentially, 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

(PLUS & args)

TODO: write docs

PUT

(PUT symbol indicator value)

Put this value as the value of the property indicated by this indicator of this symbol. Return value on success.

-

NOTE THAT there is no PUT defined in the manual, but it would have been easy to have defined it so I don’t think this fully counts as an extension.

QUOTIENT

(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.

REMAINDER

(REMAINDER x y)

TODO: write docs

RPLACA

(RPLACA cell value)

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

(RPLACD cell value)

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

(SET symbol val)

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

(SUB1 x)

TODO: write docs

TIMES

(TIMES & args)

TODO: write docs

TRACE

(TRACE s)

Add this s to the set of symbols currently being traced. If s is not a symbol or sequence of symbols, does nothing.

traced-symbols

Symbols currently being traced.

traced?

(traced? s)

Return true iff s is a symbol currently being traced, else nil.

uaf

(uaf l path)

Universal access function; l is expected to be an arbitrary LISP list, path a (clojure) list of the characters a and d. Intended to make declaring all those fiddly #'c[ad]+r' functions a bit easier

UNTRACE

(UNTRACE s)

Remove this s from the set of symbols currently being traced. If s is not a symbol or sequence of symbols, does nothing.

\ No newline at end of file +

NOTE THAT this function is overridden by an implementation in Lisp, but is currently still present for bootstrapping.

PLUS

(PLUS & args)

TODO: write docs

QUOTIENT

(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.

REMAINDER

(REMAINDER x y)

TODO: write docs

RPLACA

(RPLACA cell value)

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

(RPLACD cell value)

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

(SET symbol val)

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

(SUB1 x)

TODO: write docs

TIMES

(TIMES & args)

TODO: write docs

TRACE

(TRACE s)

Add this symbol s to the set of symbols currently being traced. If s is not a symbol, does nothing.

traced-symbols

Symbols currently being traced.

traced?

(traced? s)

Return true iff s is a symbol currently being traced, else nil.

uaf

(uaf l path)

Universal access function; l is expected to be an arbitrary LISP list, path a (clojure) list of the characters a and d. Intended to make declaring all those fiddly #'c[ad]+r' functions a bit easier

UNTRACE

(UNTRACE s)

TODO: write docs

\ No newline at end of file diff --git a/docs/codox/beowulf.interop.html b/docs/codox/beowulf.interop.html deleted file mode 100644 index cd46169..0000000 --- a/docs/codox/beowulf.interop.html +++ /dev/null @@ -1,11 +0,0 @@ - -beowulf.interop documentation

beowulf.interop

TODO: write docs

INTEROP

(INTEROP fn-symbol args)

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. -
  3. a sequence (list) of symbols forming a qualified path name bound to a function.
  4. -
-

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.

interpret-qualified-name

(interpret-qualified-name l)

For interoperation with Clojure, it will often be necessary to pass qualified names that are not representable in Lisp 1.5. This function takes a sequence in the form (PART PART PART... NAME) and returns a symbol in the form part.part.part/NAME. This symbol will then be tried in both that form and lower-cased. Names with hyphens or underscores cannot be represented with this scheme.

listify-qualified-name

(listify-qualified-name subr)

We need to be able to print something we can link to the particular Clojure function subr in a form in which Lisp 1.5 is able to read it back in and relink it.

-

This assumes subr is either 1. a string in the format #'beowulf.io/SYSIN or beowulf.io/SYSIN; or 2. something which, when coerced to a string with str, will have such a format.

to-beowulf

(to-beowulf o)

Return a beowulf-native representation of the Clojure object o. Numbers and symbols are unaffected. Collections have to be converted; strings must be converted to symbols.

to-clojure

(to-clojure l)

If l is a beowulf.cons_cell.ConsCell, return a Clojure list having the same members in the same order.

\ No newline at end of file diff --git a/docs/codox/beowulf.io.html b/docs/codox/beowulf.io.html index d5bae54..2d19239 100644 --- a/docs/codox/beowulf.io.html +++ b/docs/codox/beowulf.io.html @@ -1,13 +1,13 @@ -beowulf.io documentation

beowulf.io

Non-standard extensions to Lisp 1.5 to read and write to the filesystem.

+beowulf.io documentation

beowulf.io

Non-standard extensions to Lisp 1.5 to read and write to the filesystem.

Lisp 1.5 had only READ, which read one S-Expression at a time, and various forms of PRIN* functions, which printed to the line printer. There was also PUNCH, which wrote to a card punch. It does not seem that there was any concept of an interactive terminal.

See Appendix E, OVERLORD - THE MONITOR, and Appendix F, LISP INPUT AND OUTPUT.

For our purposes, to save the current state of the Lisp system it should be sufficient to print the current contents of the oblist to file; and to restore a previous state from file, to overwrite the contents of the oblist with data from that file.

-

Hence functions SYSOUT and SYSIN, which do just that.

default-sysout

TODO: write docs

resolve-subr

(resolve-subr entry)(resolve-subr entry prop)

If this oblist entry references a subroutine, attempt to fix up that reference.

safely-wrap-subr

(safely-wrap-subr entry)

TODO: write docs

safely-wrap-subrs

(safely-wrap-subrs objects)

TODO: write docs

SYSIN

(SYSIN)(SYSIN filename)

Read the contents of the file at this filename into the object list.

+

Hence functions SYSOUT and SYSIN, which do just that.

default-sysout

TODO: write docs

SYSIN

(SYSIN)(SYSIN filename)

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

(SYSOUT)(SYSOUT filepath)

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 strct mode.

\ No newline at end of file +

NOTE THAT this is an extension function, not available in strct mode.

SYSOUT

(SYSOUT)(SYSOUT filepath)

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 strct mode.

\ No newline at end of file diff --git a/docs/codox/beowulf.manual.html b/docs/codox/beowulf.manual.html index cd01906..bf60737 100644 --- a/docs/codox/beowulf.manual.html +++ b/docs/codox/beowulf.manual.html @@ -1,3 +1,3 @@ -beowulf.manual documentation

beowulf.manual

Experimental code for accessing the manual online.

*manual-url*

dynamic

TODO: write docs

format-page-references

(format-page-references fn-symbol)

Format page references from the manual index for the function whose name is fn-symbol.

index

This is data extracted from the index pages of Lisp 1.5 Programmer's Manual. It’s here in the hope that we can automatically link to an online PDF link to the manual when the user invokes a function probably called DOC or HELP.

page-url

(page-url page-no)

Format the URL for the page in the manual with this page-no.

\ No newline at end of file +beowulf.manual documentation

beowulf.manual

Experimental code for accessing the manual online.

*manual-url*

dynamic

TODO: write docs

format-page-references

(format-page-references fn-symbol)

Format page references from the manual index for the function whose name is fn-symbol.

index

This is data extracted from the index pages of Lisp 1.5 Programmer's Manual. It’s here in the hope that we can automatically link to an online PDF link to the manual when the user invokes a function probably called DOC or HELP.

page-url

(page-url page-no)

Format the URL for the page in the manual with this page-no.

\ No newline at end of file diff --git a/docs/codox/beowulf.oblist.html b/docs/codox/beowulf.oblist.html index 74f48e7..241acff 100644 --- a/docs/codox/beowulf.oblist.html +++ b/docs/codox/beowulf.oblist.html @@ -1,5 +1,5 @@ -beowulf.oblist documentation

beowulf.oblist

A namespace mainly devoted to the object list and other top level global variables.

+beowulf.oblist documentation

beowulf.oblist

A namespace mainly devoted to the object list and other top level global variables.

Yes, this makes little sense, but if you put them anywhere else you end up in cyclic dependency hell.

*options*

dynamic

Command line options from invocation.

NIL

The canonical empty list symbol.

TODO: this doesn’t really work, because (from Clojure) (empty? NIL) throws an exception. It might be better to subclass beowulf.cons_cell.ConsCell to create a new singleton class Nil which overrides the empty method of IPersistentCollection?

oblist

The default environment.

\ No newline at end of file diff --git a/docs/codox/beowulf.read.html b/docs/codox/beowulf.read.html index cfa7e94..115d614 100644 --- a/docs/codox/beowulf.read.html +++ b/docs/codox/beowulf.read.html @@ -1,6 +1,6 @@ -beowulf.read documentation

beowulf.read

This provides the reader required for boostrapping. It’s not a bad reader - it provides feedback on errors found in the input - but it isn’t the real Lisp reader.

+beowulf.read documentation

beowulf.read

This provides the reader required for boostrapping. It’s not a bad reader - it provides feedback on errors found in the input - but it isn’t the real Lisp reader.

Intended deviations from the behaviour of the real Lisp reader are as follows:

  1. It reads the meta-expression language MEXPR in addition to the symbolic expression language SEXPR, which I do not believe the Lisp 1.5 reader ever did;
  2. diff --git a/docs/codox/beowulf.reader.char-reader.html b/docs/codox/beowulf.reader.char-reader.html index a014787..8699ea3 100644 --- a/docs/codox/beowulf.reader.char-reader.html +++ b/docs/codox/beowulf.reader.char-reader.html @@ -1,6 +1,6 @@ -beowulf.reader.char-reader documentation

    beowulf.reader.char-reader

    Provide sensible line editing, auto completion, and history recall.

    +beowulf.reader.char-reader documentation

    beowulf.reader.char-reader

    Provide sensible line editing, auto completion, and history recall.

    None of what’s needed here is really working yet, and a pull request with a working implementation would be greatly welcomed.

    What’s needed (rough specification)

      @@ -9,5 +9,6 @@
    1. and scroll back and forward through history, but ideally I’d like this to be the Lisp history (i.e. the history of S-Expressions actually read by READ, rather than the strings which were supplied to READ);
    2. offers potential auto-completions taken from the value of (OBLIST), ideally the current value, not the value at the time the session started;
    3. and offer movement and editing within the line.
    4. -
    -

    TODO: There are multiple problems with JLine; a better solution might be to start from here: https://stackoverflow.com/questions/7931988/how-to-manipulate-control-characters

    \ No newline at end of file +

get-reader

Return a reader, first constructing it if necessary.

+

NOTE THAT this is not settled API. The existence and call signature of this function is not guaranteed in future versions.

read-chars

(read-chars)

A drop-in replacement for clojure.core/read-line, except that line editing and history should be enabled.

+

NOTE THAT this does not work yet, but it is in the API because I hope that it will work later!

\ No newline at end of file diff --git a/docs/codox/beowulf.reader.generate.html b/docs/codox/beowulf.reader.generate.html index 58d4e15..574e61e 100644 --- a/docs/codox/beowulf.reader.generate.html +++ b/docs/codox/beowulf.reader.generate.html @@ -1,6 +1,6 @@ -beowulf.reader.generate documentation

beowulf.reader.generate

Generating S-Expressions from parse trees.

+beowulf.reader.generate documentation

beowulf.reader.generate

Generating S-Expressions from parse trees.

From Lisp 1.5 Programmers Manual, page 10

Note that I’ve retyped much of this, since copy/pasting out of PDF is less than reliable. Any typos are mine.

Quote starts:

@@ -21,4 +21,4 @@ T->ff[car[x]]]]] (COND ((ATOM X) X) ((QUOTE T)(FF (CAR X)))))) -

quote ends

gen-cond

(gen-cond p context)

Generate a cond statement from this simplified parse tree fragment p; returns nil if p does not represent a (MEXPR) cond statement.

gen-cond-clause

(gen-cond-clause p context)

Generate a cond clause from this simplified parse tree fragment p; returns nil if p does not represent a cond clause.

gen-dot-terminated-list

(gen-dot-terminated-list p)

Generate a list, which may be dot-terminated, from this partial parse tree ‘p’. Note that the function acts recursively and progressively decapitates its argument, so that the argument will not always be a valid parse tree.

gen-fn-call

(gen-fn-call p context)

Generate a function call from this simplified parse tree fragment p; returns nil if p does not represent a (MEXPR) function call.

gen-iexpr

(gen-iexpr tree context)

TODO: write docs

generate

(generate p)(generate p context)

Generate lisp structure from this parse tree p. It is assumed that p has been simplified.

generate-assign

(generate-assign tree context)

Generate an assignment statement based on this tree. If the thing being assigned to is a function signature, then we have to do something different to if it’s an atom.

generate-defn

(generate-defn tree context)

TODO: write docs

generate-set

(generate-set tree context)

Actually not sure what the mexpr representation of set looks like

strip-leading-zeros

(strip-leading-zeros s)(strip-leading-zeros s prefix)

read-string interprets strings with leading zeros as octal; strip any from this string s. If what’s left is empty (i.e. there were only zeros, return "0".

\ No newline at end of file +

quote ends

gen-cond

(gen-cond p)

Generate a cond statement from this simplified parse tree fragment p; returns nil if p does not represent a (MEXPR) cond statement.

gen-cond-clause

(gen-cond-clause p)

Generate a cond clause from this simplified parse tree fragment p; returns nil if p does not represent a cond clause.

gen-dot-terminated-list

(gen-dot-terminated-list p)

Generate a list, which may be dot-terminated, from this partial parse tree ‘p’. Note that the function acts recursively and progressively decapitates its argument, so that the argument will not always be a valid parse tree.

gen-fn-call

(gen-fn-call p)

Generate a function call from this simplified parse tree fragment p; returns nil if p does not represent a (MEXPR) function call.

gen-iexpr

(gen-iexpr tree)

TODO: write docs

generate

(generate p)

Generate lisp structure from this parse tree p. It is assumed that p has been simplified.

generate-assign

(generate-assign tree)

Generate an assignment statement based on this tree. If the thing being assigned to is a function signature, then we have to do something different to if it’s an atom.

generate-defn

(generate-defn tree)

TODO: write docs

generate-set

(generate-set tree)

Actually not sure what the mexpr representation of set looks like

strip-leading-zeros

(strip-leading-zeros s)(strip-leading-zeros s prefix)

read-string interprets strings with leading zeros as octal; strip any from this string s. If what’s left is empty (i.e. there were only zeros, return "0".

\ No newline at end of file diff --git a/docs/codox/beowulf.reader.macros.html b/docs/codox/beowulf.reader.macros.html index 19c4982..510db75 100644 --- a/docs/codox/beowulf.reader.macros.html +++ b/docs/codox/beowulf.reader.macros.html @@ -1,5 +1,5 @@ -beowulf.reader.macros documentation

beowulf.reader.macros

Can I implement reader macros? let’s see!

+beowulf.reader.macros documentation

beowulf.reader.macros

Can I implement reader macros? let’s see!

We don’t need (at least, in the Clojure reader) to rewrite forms like 'FOO, because that’s handled by the parser. But we do need to rewrite things which don’t evaluate their arguments, like SETQ, because (unless LABEL does it, which I’m not yet sure of) we’re not yet able to implement things which don’t evaluate arguments.

TODO: at this stage, the following should probably also be read macros: DEFINE

*readmacros*

dynamic

TODO: write docs

expand-macros

(expand-macros form)

TODO: write docs

\ No newline at end of file diff --git a/docs/codox/beowulf.reader.parser.html b/docs/codox/beowulf.reader.parser.html index 7499c5e..92309e8 100644 --- a/docs/codox/beowulf.reader.parser.html +++ b/docs/codox/beowulf.reader.parser.html @@ -1,3 +1,3 @@ -beowulf.reader.parser documentation

beowulf.reader.parser

The actual parser, supporting both S-expression and M-expression syntax.

parse

Parse a string presented as argument into a parse tree which can then be operated upon further.

\ No newline at end of file +beowulf.reader.parser documentation

beowulf.reader.parser

The actual parser, supporting both S-expression and M-expression syntax.

parse

Parse a string presented as argument into a parse tree which can then be operated upon further.

\ No newline at end of file diff --git a/docs/codox/beowulf.reader.simplify.html b/docs/codox/beowulf.reader.simplify.html index 52fa75b..f2adfb6 100644 --- a/docs/codox/beowulf.reader.simplify.html +++ b/docs/codox/beowulf.reader.simplify.html @@ -1,4 +1,4 @@ -beowulf.reader.simplify documentation

beowulf.reader.simplify

Simplify parse trees. Be aware that this is very tightly coupled with the parser.

remove-nesting

(remove-nesting tree context)

TODO: write docs

remove-optional-space

(remove-optional-space tree)

TODO: write docs

simplify

(simplify p)

Simplify this parse tree p. If p is an instaparse failure object, throw an ex-info, with p as the value of its :failure key. Calls remove-optional-space before processing.

simplify-tree

(simplify-tree p)(simplify-tree p context)

Simplify this parse tree p. If p is an instaparse failure object, throw an ex-info, with p as the value of its :failure key.

+beowulf.reader.simplify documentation

beowulf.reader.simplify

Simplify parse trees. Be aware that this is very tightly coupled with the parser.

remove-nesting

(remove-nesting tree context)

TODO: write docs

remove-optional-space

(remove-optional-space tree)

TODO: write docs

simplify

(simplify p)

Simplify this parse tree p. If p is an instaparse failure object, throw an ex-info, with p as the value of its :failure key. Calls remove-optional-space before processing.

simplify-tree

(simplify-tree p)(simplify-tree p context)

Simplify this parse tree p. If p is an instaparse failure object, throw an ex-info, with p as the value of its :failure key.

NOTE THAT it is assumed that remove-optional-space has been run on the parse tree BEFORE it is passed to simplify-tree.

\ No newline at end of file diff --git a/docs/codox/css/default.css b/docs/codox/css/default.css index a445e91..33f78fe 100644 --- a/docs/codox/css/default.css +++ b/docs/codox/css/default.css @@ -1,28 +1,12 @@ body { font-family: Helvetica, Arial, sans-serif; font-size: 15px; - color: limegreen; - background-color: black; -} - -a { - color: lime; -} - -a:active, a:hover { - color: yellowgreen; -} - -a:visited { - color: green; } pre, code { font-family: Monaco, DejaVu Sans Mono, Consolas, monospace; font-size: 9pt; margin: 15px 0; - color: limegreen; - background-color: #111; } h1 { @@ -37,13 +21,9 @@ h2 { font-size: 25px; } -th, td { - vertical-align: top; -} - h5.license { margin: 9px 0 22px 0; - color: lime; + color: #555; font-weight: normal; font-size: 12px; font-style: italic; @@ -63,7 +43,7 @@ h5.license { left: 0; right: 0; height: 22px; - color: limegreen; + color: #f5f5f5; padding: 5px 7px; } @@ -72,8 +52,8 @@ h5.license { right: 0; bottom: 0; overflow: auto; - background: black; - color: green; + background: #fff; + color: #333; padding: 0 18px; } @@ -85,15 +65,15 @@ h5.license { } .sidebar.primary { - background: #080808; - border-right: solid 1px forestgreen; + background: #e2e2e2; + border-right: solid 1px #cccccc; left: 0; width: 250px; } .sidebar.secondary { - background: #111; - border-right: solid 1px darkgreen; + background: #f2f2f2; + border-right: solid 1px #d7d7d7; left: 251px; width: 200px; } @@ -111,8 +91,8 @@ h5.license { } #header { - background: #080808; - box-shadow: 0 0 8px rgba(192, 255, 192, 0.4); + background: #3f3f3f; + box-shadow: 0 0 8px rgba(0, 0, 0, 0.4); z-index: 100; } @@ -137,13 +117,21 @@ h5.license { text-decoration: none; } +#header a { + color: #f5f5f5; +} + +.sidebar a { + color: #333; +} + #header h2 { float: right; font-size: 9pt; font-weight: normal; margin: 4px 3px; padding: 0; - color: #5f5; + color: #bbb; } #header h2 a { @@ -158,11 +146,11 @@ h5.license { } .sidebar h3 a { - color: #4f4; + color: #444; } .sidebar h3.no-link { - color: green; + color: #636363; } .sidebar ul { @@ -187,7 +175,7 @@ h5.license { .sidebar li .no-link { display: block; - color: #7F7; + color: #777; font-style: italic; } @@ -229,8 +217,8 @@ h5.license { } .sidebar li .tree .top { - border-left: 1px solid yellowgreen; - border-bottom: 1px solid yellowgreen; + border-left: 1px solid #aaa; + border-bottom: 1px solid #aaa; height: 19px; } @@ -239,17 +227,17 @@ h5.license { } .sidebar li.branch .tree .bottom { - border-left: 1px solid yellowgreen; + border-left: 1px solid #aaa; } .sidebar.primary li.current a { - border-left: 3px solid goldenrod; - color: goldenrod; + border-left: 3px solid #a33; + color: #a33; } .sidebar.secondary li.current a { - border-left: 3px solid yellow; - color: yellow; + border-left: 3px solid #33a; + color: #33a; } .namespace-index h2 { @@ -287,7 +275,7 @@ h5.license { .public { margin: 0; - border-top: 1px solid lime; + border-top: 1px solid #e0e0e0; padding-top: 14px; padding-bottom: 6px; } @@ -305,7 +293,7 @@ h5.license { } .members h4 { - color: lime; + color: #555; font-weight: normal; font-variant: small-caps; margin: 0 0 5px 0; @@ -316,7 +304,7 @@ h5.license { padding-left: 12px; margin-top: 2px; margin-left: 7px; - border-left: 1px solid #5f5; + border-left: 1px solid #bbb; } #content .members .inner h3 { @@ -369,7 +357,7 @@ h4.dynamic { } h4.added { - color: #7acc32; + color: #508820; } h4.deprecated { @@ -409,7 +397,7 @@ h4.deprecated { .type-sig { clear: both; - color: goldenrod; + color: #088; } .type-sig pre { @@ -419,8 +407,8 @@ h4.deprecated { .usage code { display: block; + color: #008; margin: 2px 0; - color: limegreen; } .usage code:first-child { @@ -488,27 +476,27 @@ p { } .markdown pre > code, .src-link a { - border: 1px solid lime; + border: 1px solid #e4e4e4; border-radius: 2px; } .markdown code:not(.hljs), .src-link a { - background: #111; + background: #f6f6f6; } pre.deps { display: inline-block; margin: 0 10px; - border: 1px solid lime; + border: 1px solid #e4e4e4; border-radius: 2px; padding: 10px; - background-color: #111; + background-color: #f6f6f6; } .markdown hr { border-style: solid; border-top: none; - color: goldenrod; + color: #ccc; } .doc ul, .doc ol { @@ -521,12 +509,12 @@ pre.deps { } .doc table td, .doc table th { - border: 1px solid goldenrod; + border: 1px solid #dddddd; padding: 4px 6px; } .doc table th { - background: #111; + background: #f2f2f2; } .doc dl { @@ -537,7 +525,7 @@ pre.deps { font-weight: bold; margin: 0; padding: 3px 0; - border-bottom: 1px solid goldenrod; + border-bottom: 1px solid #ddd; } .doc dl dd { @@ -546,7 +534,7 @@ pre.deps { } .doc abbr { - border-bottom: 1px dotted goldenrod; + border-bottom: 1px dotted #333; font-variant: none; cursor: help; } @@ -559,5 +547,5 @@ pre.deps { font-size: 70%; padding: 1px 4px; text-decoration: none; - color: lime5bb; + color: #5555bb; } diff --git a/docs/codox/further_reading.html b/docs/codox/further_reading.html deleted file mode 100644 index 4ff9617..0000000 --- a/docs/codox/further_reading.html +++ /dev/null @@ -1,17 +0,0 @@ - -Further Reading

Further Reading

-
    -
  1. CODING for the MIT-IBM 704 COMPUTER, October 1957 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. -
  3. MIT AI Memo 1, John McCarthy, September 1958 This is, as far as I can find, the earliest specification document of the Lisp project.
  4. -
  5. Lisp 1 Programmer’s Manual, Phyllis Fox, March 1960
  6. -
  7. Lisp 1.5 Programmer’s Manual, Michael I. Levin, August 1962 This book is essential reading: it documents in some detail the first fully realised Lisp language system.
  8. -
  9. Early LISP History (1956 - 1959), Herbert Stoyan, August 1984
  10. -
  11. -

    The Roots of Lisp, Paul Graham, 2001

  12. -
  13. -

    The Revenge of the Nerds, Paul Graham, 2002 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.

    -
  14. -
\ No newline at end of file diff --git a/docs/codox/index.html b/docs/codox/index.html index 5d09c60..54a0ed5 100644 --- a/docs/codox/index.html +++ b/docs/codox/index.html @@ -1,3 +1,3 @@ -Beowulf 0.3.0

Beowulf 0.3.0

Released under the GPL-2.0-or-later

LISP 1.5 is to all Lisp dialects as Beowulf is to English literature.

Installation

To install, add the following dependency to your project or build file:

[beowulf "0.3.0"]

Topics

Namespaces

beowulf.bootstrap

Lisp as defined in Chapter 1 (pages 1-14) of the Lisp 1.5 Programmer's Manual; that is to say, a very simple Lisp language, which should, I believe, be sufficient in conjunction with the functions provided by beowulf.host, be sufficient to bootstrap the full Lisp 1.5 interpreter..

Public variables and functions:

beowulf.cons-cell

The fundamental cons cell on which all Lisp structures are built. Lisp 1.5 lists do not necessarily have a sequence as their CDR, and must have both CAR and CDR mutable, so cannot be implemented on top of Clojure lists.

beowulf.core

Essentially, the -main function and the bootstrap read-eval-print loop.

Public variables and functions:

beowulf.gendoc

Generate table of documentation of Lisp symbols and functions.

beowulf.host

provides Lisp 1.5 functions which can’t be (or can’t efficiently be) implemented in Lisp 1.5, which therefore need to be implemented in the host language, in this case Clojure.

beowulf.io

Non-standard extensions to Lisp 1.5 to read and write to the filesystem.

beowulf.manual

Experimental code for accessing the manual online.

Public variables and functions:

beowulf.oblist

A namespace mainly devoted to the object list and other top level global variables.

Public variables and functions:

beowulf.read

This provides the reader required for boostrapping. It’s not a bad reader - it provides feedback on errors found in the input - but it isn’t the real Lisp reader.

Public variables and functions:

beowulf.reader.char-reader

Provide sensible line editing, auto completion, and history recall.

Public variables and functions:

    beowulf.reader.macros

    Can I implement reader macros? let’s see!

    Public variables and functions:

    beowulf.reader.parser

    The actual parser, supporting both S-expression and M-expression syntax.

    Public variables and functions:

    beowulf.reader.simplify

    Simplify parse trees. Be aware that this is very tightly coupled with the parser.

    \ No newline at end of file +Beowulf 0.3.0-SNAPSHOT

    Beowulf 0.3.0-SNAPSHOT

    Released under the GPL-2.0-or-later

    An implementation of LISP 1.5 in Clojure.

    Installation

    To install, add the following dependency to your project or build file:

    [beowulf "0.3.0-SNAPSHOT"]

    Topics

    Namespaces

    beowulf.bootstrap

    Lisp as defined in Chapter 1 (pages 1-14) of the Lisp 1.5 Programmer's Manual; that is to say, a very simple Lisp language, which should, I believe, be sufficient in conjunction with the functions provided by beowulf.host, be sufficient to bootstrap the full Lisp 1.5 interpreter..

    beowulf.cons-cell

    The fundamental cons cell on which all Lisp structures are built. Lisp 1.5 lists do not necessarily have a sequence as their CDR, and must have both CAR and CDR mutable, so cannot be implemented on top of Clojure lists.

    beowulf.core

    Essentially, the -main function and the bootstrap read-eval-print loop.

    Public variables and functions:

    beowulf.gendoc

    Generate table of documentation of Lisp symbols and functions.

    beowulf.host

    provides Lisp 1.5 functions which can’t be (or can’t efficiently be) implemented in Lisp 1.5, which therefore need to be implemented in the host language, in this case Clojure.

    beowulf.io

    Non-standard extensions to Lisp 1.5 to read and write to the filesystem.

    Public variables and functions:

    beowulf.manual

    Experimental code for accessing the manual online.

    Public variables and functions:

    beowulf.oblist

    A namespace mainly devoted to the object list and other top level global variables.

    Public variables and functions:

    beowulf.read

    This provides the reader required for boostrapping. It’s not a bad reader - it provides feedback on errors found in the input - but it isn’t the real Lisp reader.

    Public variables and functions:

    beowulf.reader.char-reader

    Provide sensible line editing, auto completion, and history recall.

    Public variables and functions:

    beowulf.reader.macros

    Can I implement reader macros? let’s see!

    Public variables and functions:

    beowulf.reader.parser

    The actual parser, supporting both S-expression and M-expression syntax.

    Public variables and functions:

    beowulf.reader.simplify

    Simplify parse trees. Be aware that this is very tightly coupled with the parser.

    \ No newline at end of file diff --git a/docs/codox/intro.html b/docs/codox/intro.html index 0875f1d..9854ad9 100644 --- a/docs/codox/intro.html +++ b/docs/codox/intro.html @@ -1,84 +1,34 @@ -beowulf

    beowulf

    -

    Þý liste cræfte spræc

    +beowulf

    beowulf

    LISP 1.5 is to all Lisp dialects as Beowulf is to English literature.

    -

    Beowulf logo

    -

    Contents

    - -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 bahaviour - 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.

    Status

    -

    Working Lisp interpreter, but some key features not yet implemented.

    +

    Boots to REPL, but few functions yet available.

    -

    Project Target

    -

    The project target is to be able to run the Wang algorithm for the propositional calculus 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.

    -

    Some readline-like functionality would be really useful, but my attempt to integrate JLine 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

    +

    Building and Invoking

    +

    Build with

    +
    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)

    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:

    @@ -93,688 +43,590 @@ - - + + - - + + - - + + - - + + - - + + - - - - + + + + - - + + - - - - - - - - - + + - - + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - + + - - + + - - - - - - - - - - - + + + + - - + + - + - - + + - - - - - - - - - - - - - - - - - - + + + + - - + + - - + + - - + + - - + + - + - - - + + + - - + + - - + + - - - - + + + + - - + + - - - - + + + + - - - + + + - - - - + + + + - - + + - - - - - - - - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - + + - - + + - - - - - - - - - - - + + + + - - - - - - - - - - - + + + + - - + + + - - + + - - - - - - - - - - - - - - - - - - - + + + + - - + + - - + + - - + + - - + + - - - + + + - - + + - - + + - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - + + + + - - - - + + + + + - - + - - + + - - + + - - - - - - - - + - - + + - + - - - - + + + +
    NIL Lisp variable ? see manual pages 22, 69 ?
    T Lisp variable ? see manual pages 22, 69 ?
    F Lisp variable ? see manual pages 22, 69 ?
    ADD1 Host lambda function ? Host function (ADD1 X) ?
    AND Host lambda function ? 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 lambda function ? see manual pages 11, 61 Lisp function (APPEND X Y) LAMBDA-fn see manual pages 11, 61
    APPLY Host lambda function ? 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.
    ASSOC Lisp lambda function, Host lambda function ? ? 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 ? 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 lambda function ? 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 lambda function ? ? Lisp function (CAAAAR X) LAMBDA-fn ?
    CAAADR Lisp lambda function ? ? Lisp function (CAAADR X) LAMBDA-fn ?
    CAAAR Lisp lambda function ? ? Lisp function (CAAAR X) LAMBDA-fn ?
    CAADAR Lisp lambda function ? ? Lisp function (CAADAR X) LAMBDA-fn ?
    CAADDR Lisp lambda function ? ? Lisp function (CAADDR X) LAMBDA-fn ?
    CAADR Lisp lambda function ? ? Lisp function (CAADR X) LAMBDA-fn ?
    CAAR Lisp lambda function ? ? Lisp function (CAAR X) LAMBDA-fn ?
    CADAAR Lisp lambda function ? ? Lisp function (CADAAR X) LAMBDA-fn ?
    CADADR Lisp lambda function ? ? Lisp function (CADADR X) LAMBDA-fn ?
    CADAR Lisp lambda function ? ? Lisp function (CADAR X) LAMBDA-fn ?
    CADDAR Lisp lambda function ? ? Lisp function (CADDAR X) LAMBDA-fn ?
    CADDDR Lisp lambda function ? ? Lisp function (CADDDR X) LAMBDA-fn ?
    CADDR Lisp lambda function ? ? Lisp function (CADDR X) LAMBDA-fn ?
    CADR Lisp lambda function ? ? Lisp function (CADR X) LAMBDA-fn ?
    CDAAAR Lisp lambda function ? ? Lisp function (CDAAAR X) LAMBDA-fn ?
    CDAADR Lisp lambda function ? ? Lisp function (CDAADR X) LAMBDA-fn ?
    CDAAR Lisp lambda function ? ? Lisp function (CDAAR X) LAMBDA-fn ?
    CDADAR Lisp lambda function ? ? Lisp function (CDADAR X) LAMBDA-fn ?
    CDADDR Lisp lambda function ? ? Lisp function (CDADDR X) LAMBDA-fn ?
    CDADR Lisp lambda function ? ? Lisp function (CDADR X) LAMBDA-fn ?
    CDAR Lisp lambda function ? ? Lisp function (CDAR X) LAMBDA-fn ?
    CDDAAR Lisp lambda function ? ? Lisp function (CDDAAR X) LAMBDA-fn ?
    CDDADR Lisp lambda function ? ? Lisp function (CDDADR X) LAMBDA-fn ?
    CDDAR Lisp lambda function ? ? Lisp function (CDDAR X) LAMBDA-fn ?
    CDDDAR Lisp lambda function ? ? Lisp function (CDDDAR X) LAMBDA-fn ?
    CDDDDR Lisp lambda function ? ? Lisp function (CDDDDR X) LAMBDA-fn ?
    CDDDR Lisp lambda function ? ? Lisp function (CDDDR X) LAMBDA-fn ?
    CDDR Lisp lambda function ? ? Lisp function (CDDR X) LAMBDA-fn ?
    CDR Host lambda function ? 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 lambda function ? Host function (CONS CAR CDR) Construct a new instance of cons cell with this car and cdr.
    CONSP Host lambda function ? ? Return T if object o is a cons cell, else F. NOTE THAT this is an extension function, not available in strct 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 Lisp function (COPY X) LAMBDA-fn see manual pages 62
    DEFINE Host lambda function ? 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 association list of symbols to lambda functions. See page 58 of the manual. 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 lambda function ? Host function (DIFFERENCE X Y) ?
    DIVIDE Lisp lambda function ? 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 Lisp function (DIVIDE X Y) LAMBDA-fn see manual pages 26, 64
    ERROR Host lambda function ? Host function (ERROR & ARGS) PSEUDO-FUNCTION Throw an error
    EQ Host lambda function ? 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 lambda function ? 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 lambda function ? 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. 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. 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 lambda function ? ? Lisp function (FACTORIAL N) LAMBDA-fn ?
    FIXP Host lambda function ? Host function (FIXP X) PREDICATE ?
    GENSYM Host lambda function ? Host function (GENSYM ) 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. Lisp function (GET X Y) LAMBDA-fn see manual pages 41, 59
    GREATERP Host lambda function ? Host function (GREATERP X Y) PREDICATE ?
    INTEROP Host lambda function ? ? ? 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 lambda function ? ? Lisp function (INTERSECTION X Y) LAMBDA-fn ?
    LENGTH Lisp lambda function ? see manual pages 62 Lisp function (LENGTH L) LAMBDA-fn see manual pages 62
    LESSP Host lambda function ? Host function (LESSP X Y) PREDICATE ?
    MAPLIST Lisp lambda function ? FUNCTIONAL see manual pages 20, 21, 63
    MEMBER Lisp lambda function ? PREDICATE see manual pages 11, 62 Lisp function (MEMBER A X) LAMBDA-fn see manual pages 11, 62
    MINUSP Lisp lambda function ? PREDICATE see manual pages 26, 64 Lisp function (MINUSP X) LAMBDA-fn see manual pages 26, 64
    NOT Lisp lambda function ? PREDICATE see manual pages 21, 23, 58 Lisp function (NOT X) LAMBDA-fn see manual pages 21, 23, 58
    NULL Lisp lambda function ? PREDICATE see manual pages 11, 57 Lisp function (NULL X) LAMBDA-fn see manual pages 11, 57
    NUMBERP Host lambda function ? Host function (NUMBERP X) PREDICATE ?
    OBLIST Host lambda function ? 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 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. Lisp function (ONEP X) LAMBDA-fn see manual pages 26, 64
    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. Eessentially, 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. Lisp function (PAIR X Y) LAMBDA-fn see manual pages 60
    PLUS Host lambda function ? Host function (PLUS & ARGS) ?
    PRETTY Lisp variable ? ? (PRETTY) ?
    PRINT Lisp variable ? 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 PROGs 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 A3except 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 Lisp function (PROP X Y U) LAMBDA-fn see manual pages 59
    QUOTIENT Host lambda function ? 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 lambda function ? Lisp variable ? (RANGE (LAMBDA (N M) (COND ((LESSP M N) (QUOTE NIL)) ((QUOTE T) (CONS N (RANGE (ADD1 N) M)))))) ?
    READ Host lambda function ? 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 lambda function ? Host function (REMAINDER X Y) ?
    REPEAT Lisp lambda function ? ? Lisp function (REPEAT N X) LAMBDA-fn ?
    RPLACA Host lambda function ? 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 lambda function ? 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)
    SEARCH Lisp lambda function ? FUNCTIONAL see manual pages 63
    SET Host lambda function ? 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 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 Lisp function (SUB1 N) LAMBDA-fn see manual pages 26, 64
    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. 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 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 strct mode. 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 see manual pages 65, 84 ?
    TIMES Host lambda function ? Host function (TIMES & ARGS) ?
    TRACE Host lambda function ? Host function (TRACE S) 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 ? ? ? Add this symbol s to the set of symbols currently being traced. If s is not a symbol, does nothing.
    UNTRACE Host lambda function ? Host function (UNTRACE S) 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 Lisp function (ZEROP N) LAMBDA-fn see manual pages 26, 64
    @@ -803,18 +655,19 @@
  • It reads the meta-expression language MEXPR in addition to the symbolic expression language SEXPR, which I do not believe the Lisp 1.5 reader ever did;
  • It treats everything between a double semi-colon and an end of line as 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 than legend had led me to believe. The language is remarkably close to Portable Standard Lisp which is in my opinion one of the best and most usable early Lisp implementations.

    What’s even more surprising is how faithful a reimplementation of Lisp 1.5 the first Lisp dialect I learned, Acornsoft Lisp, turns out to have been.

    I’m convinced you could still use Lisp 1.5 for interesting and useful software (which isn’t to say that modern Lisps aren’t better, but this is software which is almost sixty years old).

    Installation

    -

    Download the latest release ‘uberjar’ and run it using:

    -
        java -jar <path name of uberjar>
    -
    -

    Or clone the source and build it using:

    -
        lein uberjar`
    -
    -

    To build it you will require to have Leiningen installed.

    +

    At present, clone the source and build it using

    +

    lein uberjar.

    +

    You will require to have Leiningen installed.

    Input/output

    Lisp 1.5 greatly predates modern computers. It had a facility to print to a line printer, or to punch cards on a punch-card machine, and it had a facility to read system images in from tape; but there’s no file I/O as we would currently understand it, and, because there are no character strings and the valid characters within an atom are limited, it isn’t easy to compose a sensible filename.

    I’ve provided two functions to work around this problem.

    @@ -827,9 +680,6 @@

    The Lisp 1.5 Programmer's Manual is still in print, ISBN 13 978-0-262-13011-0; but it’s also available online.

    Other Lisp 1.5 resources

    The main resource I’m aware of is the Software Preservation Society’s site, here. It has lots of fascinating stuff including full assembler listings for various obsolete 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 (source code here). It even has a working compiler!

    -

    History resources

    -

    I’m compiling a list of links to historical documents on Lisp 1.5.

    +

    I’m not at this time aware of any other working Lisp 1.5 implementations.

    License

    Copyright © 2019 Simon Brooke. Licensed under the GNU General Public License, version 2.0 or (at your option) any later version.

    \ No newline at end of file diff --git a/docs/codox/mexpr.html b/docs/codox/mexpr.html index 7692fe9..c8d104f 100644 --- a/docs/codox/mexpr.html +++ b/docs/codox/mexpr.html @@ -1,6 +1,6 @@ -Interpreting M-Expressions

    Interpreting M-Expressions

    +Interpreting M-Expressions

    Interpreting M-Expressions

    M-Expressions (‘mexprs’) are the grammar which John McCarthy origininally used to write Lisp, and the grammar in which many of the function definitions in the Lisp 1.5 Programmer’s Manual are stated. However, I have not seen anywhere a claim that Lisp 1.5 could read M-Expressions, and it is not clear to me whether it was even planned that it should do so, although the discussion on page 10 suggests that it was.

    Rather, it seems to me possible that M-Expressions were only ever a grammar intended to be written on paper, like Backus Naur Form, to describe and to reason about algorithms. I think at the point at which the M-Expression grammar was written, the idea of the universal Lisp function

    I set out to make Beowulf read M-Expressions essentially out of curiousity, to see whether it could be done. I had this idea that if it could be done, I could implement most of Lisp 1.5 simply by copying in the M-Expression definitions out of the manual.

    diff --git a/docs/codox/values.html b/docs/codox/values.html index 1bfdc12..2dd0ca3 100644 --- a/docs/codox/values.html +++ b/docs/codox/values.html @@ -1,10 +1,9 @@ -The properties of the system, and their values

    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.

    +Understanding values and properties

    Understanding values and properties

    +

    Lisp is the list processing language; that is what it 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.

    But how is a list, in a computer, actually implemented?

    -

    They’re implemented as pairs, or, as the manual sometimes rather delightfully called them, ‘doublets’. Pairs of what? Pairs of pointers. Of the two pointers of a pair, the first points to the current entry of the list, and the second, by default, points to the remainder of the list, or, if the end of the list has been reached, to a special datum known as NIL which among other things indicates that the end of the list has been reached. The pair itself is normally referred to as a ‘cons cell’ for reasons which are nerdy and not important just now (all right, because they are constructed using a function called cons, which is in itself believed to be simply an abbreviation of ‘construct’).

    +

    They’re implemented as pairs, or, as the manual sometimes rather delightfully called them, ‘doublets’. Pairs of what? Pairs of pointers. Of the two pointers of a pair, the first points to the current entry of the list, and the second, by default, points to the remainder of the list, or, if the end of the list has been reached, to a special datum known as NIL which among other things indicates that the end of the list has been reached. The pair itself is normally referred to as a ‘cons cell’ for reasons which are nerdy and not important just now (all right, because they are constructed using a function called cons, which is in itself simply and abbreviation of ‘construct’).

    Two functions are used to access the two pointers of the cell. In modern Lisps these functions are called first and rest, because a lot of people who aren’t greybeards find these names easier. But they aren’t the original names. The original names were CAR and CDR.

    Why?

    History

    @@ -35,18 +34,6 @@ RLN | | oo 7 a | O14 (read lines O and 1)

    Of course, this isn’t proof. If CAR and CDR used here are standard IBM 704 assembler mnemonics – as I believe they are – then what is CONS? It’s used in a syntactically identical way. If it also is an assembler mnemonic, then it’s hard to believe that, as legend relates, it is short for ‘construct’; on the other hand, if it’s a label representing an entry point into a subroutine, then why should CAR and CDR not also be labels?

    -
    -

    Edited 3rd April to add: I’ve found a document, not related to Lisp (although John McCarthy is credited as one of the authors), which does confirm – or strictly, amend – the story. This is the CODING for the MIT-IBM 704 COMPUTER, dating from October 1957. The registers of the 704 were divided into four parts, named respectively the prefix part, the address part, the tag part, and the decrement part, of 3, 15, 3, and 15 bits respectively. The decrement part was not used in addressing; that part of the folklore I was taught isn’t right. But the names are correct. Consider this excerpt :

    -
    -

    The address, tag and decrement parts of symbolic instructions are given in that order. In some cases the decrement, tag or address parts are not necessary; therefore the following combinations where OP represents the instruction abbreviation are permissible.

    -
    -

    This doesn’t prove there were individual machine instructions with the mnemonics CAR and CDR; in fact, I’m going to say with some confidence that there were not, by reference to the table of instructions appended to the same document. The instructions do have three letter mnemonics, and they do use ‘A’ and ‘D’ as abbreviations for ‘address’ and ‘decrement’ respectively, but CAR and CDR are not included.

    -

    So it seems probable that CAR and CDR were labels for subroutines, as I hypothesised above. But they were quite likely pre-existing subroutines, in use before the instantiation of the Lisp project, because they would be generally useful; and the suggestion that they are contractions of ‘contents of the address part’ and ‘contents of the decrement part’, respectively, seem confirmed.

    -

    And, going further down the rabbit hole, there’s this. In 1957, before work on the Lisp project started, McCarthy was writing functions to add list processing to the then-new FORTRAN language, on the very same IBM 704 machine.

    -
    -

    in this time any function that delivered integer values had to have a first letter X. Any function (as opposited to subroutines) had to have a last letter F in its name. Therefore the functions selecting parts of the IBM704 memory register (word) were introduced to be XCSRF, XCPRF, XCDRF, XCTRF and XCARF

    -
    -

    I think that the answer has to be that if CAR and CDR had been named by the early Lisp team – John McCarthy and his immediate colleagues – they would not have been named as they were. If not FRST and REST, as in more modern Lisps, then something like P1 and P2. CAR and CDR are distinctive and memorable (and therefore in my opinion worth preserving) because they very specifically name the parts of a cons cell and of nothing else.

    Let’s be clear, here: when CAR and CDR are used in Lisp, they are returning pointers, certainly – but not in the sense that one points to a page and the other to a word. Each is an offset into a cell array, which is almost certainly an array of single 36 bit words held on a single page. So both are in effect being used as decrements. Their use in Lisp is an overload onto their original semantic meaning; they are no longer being used for the purpose for which they are named.

    As far as I can tell, these names first appear in print in 1960, both in the Lisp 1 Programmer’s Manual referenced above, and in McCarthy’s paper Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I. The paper was published in April so was presumably written in 1959

    @@ -104,14 +91,7 @@ O14 (read lines O and 1)

    There’s a view in modern software theory – with which I strongly hold – that data should be immutable. Data that changes under you is the source of all sorts of bugs. And in modern multi threaded systems, the act of reading a datum whilst some other process is writing it, or worse, two processes attempting simultaneously to write the same datum, is a source of data corruption and even crashes. So I’m very wary of mutable data; and, in modern systems where we normally have a great deal of space and a lot of processor power, making fresh copies of data structures containing the change we wanted to make is a reasonable price to pay for avoiding a whole class of bugs.

    But early software was not like that. It was always constrained by the limits of the hardware on which it ran, to a degree that we are not. And the experience that we now have of the problems caused by mutable data, they did not have. So it’s core to the design of Lisp 1.5 that its lists are mutable; and, indeed, one of the biggest challenges in writing Beowulf has been implementing mutable lists in Clojure, a language carefully designed to prevent them.

    But, just because Lisp 1.5 lists can be mutable, should they be? And when should they be?

    -

    The problem here is that spine of the system I talked about earlier. If we build the execution stack on top of the oblist – as at present I do – then if we make a new version of the oblist with changes in it, the new changes will not be in the copy of the oblist that the stack is built on top of; and consequently, they’ll be invisible to the running program.

    -

    What I do at present, and what I think may be good enough, is that each time execution returns to the read-eval-print loop, the REPL, the user’s command line, I rebuild a new execution stack on the top of the oblist as it exists now. So, if the last operation modified the oblist, the next operation will see the new, modified version. But if someone tried to run some persistent program which was writing stuff to property values and hoping to read them back in the same computation, that wouldn’t work, and it would be a very hard bug to trace down.

    -

    So my options are:

    -
      -
    1. To implement PUT and GET in Clojure, so that they can operate on the current copy of the object list, not the one at the base of the stack. I’m slightly unwilling to do that, because my objective is to make Beowulf ultimately as self-hosting as possible.
    2. -
    3. To implement PUT and GET in Lisp, and have them destructively modify the working copy of the object list.
    4. -
    -

    Neither of these particularly appeal.

    +

    The problem here is that spine of the system I talked about earlier.

    How property lists should work

    I’m still not fully understanding how property lists in Lisp 1.5 are supposed to work.

    List format

    @@ -200,64 +180,5 @@ O14 (read lines O and 1)

    (They wrote amazingly clean code, those old masters. I could tell you a story about Chris Burton, the train, and the printer driver, that software people of today simply would not believe. But it’s true. And I think that what taught them that discipline was the high cost of even small errors.)

    Lisp 1.5 doesn’t have PUT, PUTPROP or DEFUN because setting properties individually, defining functions individually one at a time, was not something they ever thought about doing. And in learning that, I’ve learned more than I ever expected to about the real nature of Lisp 1.5, and the (great) people who wrote it.


    -

    Deeper delving

    -

    After writing, and publishing, this essay, I went on procrastinating, which is what I do when I’m sure I’m missing something; and to procrastinate, I went on reading the earliest design documents of Lisp I could find. And so I came across the MIT AI team’s first ever memo, written by John McCarthy in September 1958. And in that, I find this:

    -
    -

    3.2.1. First we have those that extract parts of a 704 word and form a word from parts. We shall distinguish the following parts of a word and indicate each of them by a characteristic letter.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Letter Description
    w the whole word
    p the prefix (bits s, 1, 2)
    i the indicator (bits 1 and 2)
    s the sign bit
    d the decrement (bits 3-17)
    t the tag (bits 18-20)
    a the address (bits 21-35)
    -
    -

    In the discussion of functions which access properties on page 58 of the Lisp 1.5 programmer’s manual, the word ‘indicator’ is used in preference to ‘symbol’ for the name of a property: for example

    -
    -

    The function deflist is a more general defining function. Its first argument is a list of pairs as for define. Its second argument is the indicator that is to be used. After deflist has been executed with (ui vi) among its first argument, the property list of ui will begin:

    -

    If deflist or define is used twice on the same object with the same indicator, the old value will be replaced by the new one.

    -
    -

    (my emphasis).

    -

    That use of ‘indicator’ has been nagging at me for a week. It looks like a term of art. If it’s just an ordinary atomic symbol, why isn’t it called a symbol?

    -

    Is it an indicator in the special sense of the indicator part of the machine word? If it were, then the property list could just be a flat list of values. And what’s been worrying and surprising me is that property lists are shown in the manual as flat lists. Eureka? I don’t think so.

    -

    The reason I don’t think so is that there are only two bits in the indicator part of the word, so only four distinct values; whereas we know that Lisp 1.5 has (at least) five distinct indicator values, APVAL, EXPR, FEXPR, SUBR and FSUBR.

    -

    Furthermore, on page 39, we have:

    -
    -

    A property list is characterized by having the special constant 777778 (i. e., minus 1) as the first element of the list. The rest of the list contains various properties of the atomic symbol. Each property is preceded by an atomic symbol which is called its indicator.

    -
    -

    (again, my emphasis)

    -

    But I’m going to hypothesise that the properties were originally intended to be discriminated by the indicator bits in the cons cell, that they were originally coded that way, and that there was some code which depended on property lists being flat lists; and that, when it was discovered that four indicators were not enough and that something else was going to have to be used, the new format of the property list using atomic symbols as indicators was bodged in.

    -

    So what this is about is I’ve spent most of a whole day procrastinating, because I’m not exactly sure how I’m going to make the change I’ve got to make. Versions of Beowulf up to and including 0.2.1 used the naive understanding of the architecture; version 0.3.0 should use the corrected version. But before it can, I need to be reasonably confident that I understand what the correct solution is.

    -

    I shall implement PUT, even though it isn’t in the spec, because it’s a useful building block on which to build DEFINE and DEFLIS, both of which are. And also, because PUT would have been very easy for the Lisp 1.5 implementers to implement, if it had been relevant to their working environment. And I shall implement property list as flat lists of interleaved ‘indicator’ symbols and values, even with that nonsense 777778 as a prefix, because now I know (or think I know) that it was a bodge, it seems right in the spirit of historical reconstruction to reconstruct the bodge.

    \ No newline at end of file +

    I shall implement PUT, even though it isn’t in the spec, because it’s a useful building block on which to build DEFINE and DEFLIS, both of which are. And also, because PUT would have been very easy for the Lisp 1.5 implementers to implement, if it had been relevant to their working environment.

    \ No newline at end of file diff --git a/docs/favicon.ico b/docs/favicon.ico deleted file mode 100644 index 1465b68..0000000 Binary files a/docs/favicon.ico and /dev/null differ diff --git a/docs/img/beowulf_logo.png b/docs/img/beowulf_logo.png deleted file mode 100644 index 7ec739c..0000000 Binary files a/docs/img/beowulf_logo.png and /dev/null differ diff --git a/docs/img/beowulf_logo.xcf b/docs/img/beowulf_logo.xcf deleted file mode 100644 index 0d2fb32..0000000 Binary files a/docs/img/beowulf_logo.xcf and /dev/null differ diff --git a/docs/img/beowulf_logo_favicon.png b/docs/img/beowulf_logo_favicon.png deleted file mode 100644 index 660bdbe..0000000 Binary files a/docs/img/beowulf_logo_favicon.png and /dev/null differ diff --git a/docs/img/beowulf_logo_med.png b/docs/img/beowulf_logo_med.png deleted file mode 100644 index 3af5698..0000000 Binary files a/docs/img/beowulf_logo_med.png and /dev/null differ diff --git a/docs/index.html b/docs/index.html deleted file mode 100644 index e54cf99..0000000 --- a/docs/index.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - Beowulf: Documentation - - - -

    Beowulf: Documentation

    - - - diff --git a/project.clj b/project.clj index b57eeb4..0989300 100644 --- a/project.clj +++ b/project.clj @@ -1,37 +1,30 @@ -(defproject beowulf "0.3.0" - :aot :all +(defproject beowulf "0.3.0-SNAPSHOT" :cloverage {:output "docs/cloverage" :ns-exclude-regex [#"beowulf\.gendoc" #"beowulf\.scratch"]} - :codox {:html {:transforms [[:head] [:append - [:link {:rel "icon" - :type "image/x-icon" - :href "../img/beowulf_logo_favicon.png"}]]]} - :metadata {:doc "**TODO**: write docs" + :codox {:metadata {:doc "**TODO**: write docs" :doc/format :markdown} :output-path "docs/codox" - :source-uri "https://github.com/simon-brooke/beowulf/blob/master/{filepath}#L{line}" - ;; :themes [:journeyman] - } - :description "LISP 1.5 is to all Lisp dialects as Beowulf is to English literature." + :source-uri "https://github.com/simon-brooke/beowulf/blob/master/{filepath}#L{line}"} + :description "An implementation of LISP 1.5 in Clojure" :license {:name "GPL-2.0-or-later" :url "https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html"} :dependencies [[org.clojure/clojure "1.11.1"] [org.clojure/math.combinatorics "0.2.0"] ;; not needed in production builds [org.clojure/math.numeric-tower "0.0.5"] [org.clojure/tools.cli "1.0.214"] - [org.clojure/tools.trace "0.7.11"] [clojure.java-time "1.2.0"] [environ "1.2.0"] [instaparse "1.4.12"] -;; [org.jline/jline "3.23.0"] + [org.jline/jline "3.23.0"] [rhizome "0.2.9"] ;; not needed in production builds ] - :main beowulf.core + :main ^:skip-aot beowulf.core :plugins [[lein-cloverage "1.2.2"] [lein-codox "0.10.7"] [lein-environ "1.1.0"]] - :profiles {:jar {:aot :all} - :uberjar {:aot :all}} + :profiles {:uberjar {:aot :all + :omit-source true + :uberjar-exclusions [#"beowulf\.scratch"]}} :release-tasks [["vcs" "assert-committed"] ["change" "version" "leiningen.release/bump-version" "release"] ["vcs" "commit"] @@ -41,5 +34,6 @@ ["uberjar"] ["change" "version" "leiningen.release/bump-version"] ["vcs" "commit"]] + :target-path "target/%s" :url "https://github.com/simon-brooke/the-great-game") diff --git a/resources/codox/themes/journeyman/css/default.css b/resources/codox/themes/journeyman/css/default.css deleted file mode 100644 index a445e91..0000000 --- a/resources/codox/themes/journeyman/css/default.css +++ /dev/null @@ -1,563 +0,0 @@ -body { - font-family: Helvetica, Arial, sans-serif; - font-size: 15px; - color: limegreen; - background-color: black; -} - -a { - color: lime; -} - -a:active, a:hover { - color: yellowgreen; -} - -a:visited { - color: green; -} - -pre, code { - font-family: Monaco, DejaVu Sans Mono, Consolas, monospace; - font-size: 9pt; - margin: 15px 0; - color: limegreen; - background-color: #111; -} - -h1 { - font-weight: normal; - font-size: 29px; - margin: 10px 0 2px 0; - padding: 0; -} - -h2 { - font-weight: normal; - font-size: 25px; -} - -th, td { - vertical-align: top; -} - -h5.license { - margin: 9px 0 22px 0; - color: lime; - font-weight: normal; - font-size: 12px; - font-style: italic; -} - -.document h1, .namespace-index h1 { - font-size: 32px; - margin-top: 12px; -} - -#header, #content, .sidebar { - position: fixed; -} - -#header { - top: 0; - left: 0; - right: 0; - height: 22px; - color: limegreen; - padding: 5px 7px; -} - -#content { - top: 32px; - right: 0; - bottom: 0; - overflow: auto; - background: black; - color: green; - padding: 0 18px; -} - -.sidebar { - position: fixed; - top: 32px; - bottom: 0; - overflow: auto; -} - -.sidebar.primary { - background: #080808; - border-right: solid 1px forestgreen; - left: 0; - width: 250px; -} - -.sidebar.secondary { - background: #111; - border-right: solid 1px darkgreen; - left: 251px; - width: 200px; -} - -#content.namespace-index, #content.document { - left: 251px; -} - -#content.namespace-docs { - left: 452px; -} - -#content.document { - padding-bottom: 10%; -} - -#header { - background: #080808; - box-shadow: 0 0 8px rgba(192, 255, 192, 0.4); - z-index: 100; -} - -#header h1 { - margin: 0; - padding: 0; - font-size: 18px; - font-weight: lighter; - text-shadow: -1px -1px 0px #333; -} - -#header h1 .project-version { - font-weight: normal; -} - -.project-version { - padding-left: 0.15em; -} - -#header a, .sidebar a { - display: block; - text-decoration: none; -} - -#header h2 { - float: right; - font-size: 9pt; - font-weight: normal; - margin: 4px 3px; - padding: 0; - color: #5f5; -} - -#header h2 a { - display: inline; -} - -.sidebar h3 { - margin: 0; - padding: 10px 13px 0 13px; - font-size: 19px; - font-weight: lighter; -} - -.sidebar h3 a { - color: #4f4; -} - -.sidebar h3.no-link { - color: green; -} - -.sidebar ul { - padding: 7px 0 6px 0; - margin: 0; -} - -.sidebar ul.index-link { - padding-bottom: 4px; -} - -.sidebar li { - display: block; - vertical-align: middle; -} - -.sidebar li a, .sidebar li .no-link { - border-left: 3px solid transparent; - padding: 0 10px; - white-space: nowrap; -} - -.sidebar li .no-link { - display: block; - color: #7F7; - font-style: italic; -} - -.sidebar li .inner { - display: inline-block; - padding-top: 7px; - height: 24px; -} - -.sidebar li a, .sidebar li .tree { - height: 31px; -} - -.depth-1 .inner { padding-left: 2px; } -.depth-2 .inner { padding-left: 6px; } -.depth-3 .inner { padding-left: 20px; } -.depth-4 .inner { padding-left: 34px; } -.depth-5 .inner { padding-left: 48px; } -.depth-6 .inner { padding-left: 62px; } - -.sidebar li .tree { - display: block; - float: left; - position: relative; - top: -10px; - margin: 0 4px 0 0; - padding: 0; -} - -.sidebar li.depth-1 .tree { - display: none; -} - -.sidebar li .tree .top, .sidebar li .tree .bottom { - display: block; - margin: 0; - padding: 0; - width: 7px; -} - -.sidebar li .tree .top { - border-left: 1px solid yellowgreen; - border-bottom: 1px solid yellowgreen; - height: 19px; -} - -.sidebar li .tree .bottom { - height: 22px; -} - -.sidebar li.branch .tree .bottom { - border-left: 1px solid yellowgreen; -} - -.sidebar.primary li.current a { - border-left: 3px solid goldenrod; - color: goldenrod; -} - -.sidebar.secondary li.current a { - border-left: 3px solid yellow; - color: yellow; -} - -.namespace-index h2 { - margin: 30px 0 0 0; -} - -.namespace-index h3 { - font-size: 16px; - font-weight: bold; - margin-bottom: 0; -} - -.namespace-index .topics { - padding-left: 30px; - margin: 11px 0 0 0; -} - -.namespace-index .topics li { - padding: 5px 0; -} - -.namespace-docs h3 { - font-size: 18px; - font-weight: bold; -} - -.public h3 { - margin: 0; - float: left; -} - -.usage { - clear: both; -} - -.public { - margin: 0; - border-top: 1px solid lime; - padding-top: 14px; - padding-bottom: 6px; -} - -.public:last-child { - margin-bottom: 20%; -} - -.members .public:last-child { - margin-bottom: 0; -} - -.members { - margin: 15px 0; -} - -.members h4 { - color: lime; - font-weight: normal; - font-variant: small-caps; - margin: 0 0 5px 0; -} - -.members .inner { - padding-top: 5px; - padding-left: 12px; - margin-top: 2px; - margin-left: 7px; - border-left: 1px solid #5f5; -} - -#content .members .inner h3 { - font-size: 12pt; -} - -.members .public { - border-top: none; - margin-top: 0; - padding-top: 6px; - padding-bottom: 0; -} - -.members .public:first-child { - padding-top: 0; -} - -h4.type, -h4.dynamic, -h4.added, -h4.deprecated { - float: left; - margin: 3px 10px 15px 0; - font-size: 15px; - font-weight: bold; - font-variant: small-caps; -} - -.public h4.type, -.public h4.dynamic, -.public h4.added, -.public h4.deprecated { - font-size: 13px; - font-weight: bold; - margin: 3px 0 0 10px; -} - -.members h4.type, -.members h4.added, -.members h4.deprecated { - margin-top: 1px; -} - -h4.type { - color: #717171; -} - -h4.dynamic { - color: #9933aa; -} - -h4.added { - color: #7acc32; -} - -h4.deprecated { - color: #880000; -} - -.namespace { - margin-bottom: 30px; -} - -.namespace:last-child { - margin-bottom: 10%; -} - -.index { - padding: 0; - font-size: 80%; - margin: 15px 0; - line-height: 16px; -} - -.index * { - display: inline; -} - -.index p { - padding-right: 3px; -} - -.index li { - padding-right: 5px; -} - -.index ul { - padding-left: 0; -} - -.type-sig { - clear: both; - color: goldenrod; -} - -.type-sig pre { - padding-top: 10px; - margin: 0; -} - -.usage code { - display: block; - margin: 2px 0; - color: limegreen; -} - -.usage code:first-child { - padding-top: 10px; -} - -p { - margin: 15px 0; -} - -.public p:first-child, .public pre.plaintext { - margin-top: 12px; -} - -.doc { - margin: 0 0 26px 0; - clear: both; -} - -.public .doc { - margin: 0; -} - -.namespace-index .doc { - margin-bottom: 20px; -} - -.namespace-index .namespace .doc { - margin-bottom: 10px; -} - -.markdown p, .markdown li, .markdown dt, .markdown dd, .markdown td { - line-height: 22px; -} - -.markdown li { - padding: 2px 0; -} - -.markdown h2 { - font-weight: normal; - font-size: 25px; - margin: 30px 0 10px 0; -} - -.markdown h3 { - font-weight: normal; - font-size: 20px; - margin: 30px 0 0 0; -} - -.markdown h4 { - font-size: 15px; - margin: 22px 0 -4px 0; -} - -.doc, .public, .namespace .index { - max-width: 680px; - overflow-x: visible; -} - -.markdown pre > code { - display: block; - padding: 10px; -} - -.markdown pre > code, .src-link a { - border: 1px solid lime; - border-radius: 2px; -} - -.markdown code:not(.hljs), .src-link a { - background: #111; -} - -pre.deps { - display: inline-block; - margin: 0 10px; - border: 1px solid lime; - border-radius: 2px; - padding: 10px; - background-color: #111; -} - -.markdown hr { - border-style: solid; - border-top: none; - color: goldenrod; -} - -.doc ul, .doc ol { - padding-left: 30px; -} - -.doc table { - border-collapse: collapse; - margin: 0 10px; -} - -.doc table td, .doc table th { - border: 1px solid goldenrod; - padding: 4px 6px; -} - -.doc table th { - background: #111; -} - -.doc dl { - margin: 0 10px 20px 10px; -} - -.doc dl dt { - font-weight: bold; - margin: 0; - padding: 3px 0; - border-bottom: 1px solid goldenrod; -} - -.doc dl dd { - padding: 5px 0; - margin: 0 0 5px 10px; -} - -.doc abbr { - border-bottom: 1px dotted goldenrod; - font-variant: none; - cursor: help; -} - -.src-link { - margin-bottom: 15px; -} - -.src-link a { - font-size: 70%; - padding: 1px 4px; - text-decoration: none; - color: lime5bb; -} diff --git a/resources/codox/themes/journeyman/css/highlight.css b/resources/codox/themes/journeyman/css/highlight.css deleted file mode 100644 index d0cdaa3..0000000 --- a/resources/codox/themes/journeyman/css/highlight.css +++ /dev/null @@ -1,97 +0,0 @@ -/* -github.com style (c) Vasily Polovnyov -*/ - -.hljs { - display: block; - overflow-x: auto; - padding: 0.5em; - color: #333; - background: #f8f8f8; -} - -.hljs-comment, -.hljs-quote { - color: #998; - font-style: italic; -} - -.hljs-keyword, -.hljs-selector-tag, -.hljs-subst { - color: #333; - font-weight: bold; -} - -.hljs-number, -.hljs-literal, -.hljs-variable, -.hljs-template-variable, -.hljs-tag .hljs-attr { - color: #008080; -} - -.hljs-string, -.hljs-doctag { - color: #d14; -} - -.hljs-title, -.hljs-section, -.hljs-selector-id { - color: #900; - font-weight: bold; -} - -.hljs-subst { - font-weight: normal; -} - -.hljs-type, -.hljs-class .hljs-title { - color: #458; - font-weight: bold; -} - -.hljs-tag, -.hljs-name, -.hljs-attribute { - color: #000080; - font-weight: normal; -} - -.hljs-regexp, -.hljs-link { - color: #009926; -} - -.hljs-symbol, -.hljs-bullet { - color: #990073; -} - -.hljs-built_in, -.hljs-builtin-name { - color: #0086b3; -} - -.hljs-meta { - color: #999; - font-weight: bold; -} - -.hljs-deletion { - background: #fdd; -} - -.hljs-addition { - background: #dfd; -} - -.hljs-emphasis { - font-style: italic; -} - -.hljs-strong { - font-weight: bold; -} diff --git a/resources/codox/themes/journeyman/theme.edn b/resources/codox/themes/journeyman/theme.edn deleted file mode 100644 index e1fdd5e..0000000 --- a/resources/codox/themes/journeyman/theme.edn +++ /dev/null @@ -1 +0,0 @@ -{:resources ["css/default.css" "css/highlight.css"]} \ No newline at end of file diff --git a/resources/lisp1.5.lsp b/resources/lisp1.5.lsp index e56bc7d..ddf36b2 100644 --- a/resources/lisp1.5.lsp +++ b/resources/lisp1.5.lsp @@ -12,7 +12,7 @@ 32767 EXPR (LAMBDA - (X Y) (COND ((NULL X) Y) (T (CONS (CAR X) (APPEND (CDR X) Y)))))) + (X Y) (COND ((NULL X) Y) ((QUOTE T) (CONS (CAR X) (APPEND (CDR X) Y)))))) (APPLY 32767 SUBR (BEOWULF BOOTSTRAP APPLY)) (ASSOC 32767 @@ -20,9 +20,9 @@ (LAMBDA (X L) (COND - ((NULL L) NIL) + ((NULL L) (QUOTE NIL)) ((AND (CONSP (CAR L)) (EQ (CAAR L) X)) (CAR L)) - (T (ASSOC X (CDR L))))) + ((QUOTE T) (ASSOC X (CDR L))))) SUBR (BEOWULF HOST ASSOC)) (ATOM 32767 SUBR (BEOWULF HOST ATOM)) (CAR 32767 SUBR (BEOWULF HOST CAR)) @@ -63,14 +63,14 @@ (LAMBDA (X) (COND - ((NULL X) NIL) - ((ATOM X) X) (T (CONS (COPY (CAR X)) (COPY (CDR X))))))) + ((NULL X) (QUOTE NIL)) + ((ATOM X) X) ((QUOTE T) (CONS (COPY (CAR X)) (COPY (CDR X))))))) (DEFINE 32767 SUBR (BEOWULF HOST DEFINE)) (DIFFERENCE 32767 SUBR (BEOWULF HOST DIFFERENCE)) (DIVIDE 32767 EXPR - (LAMBDA (X Y) (CONS (QUOTIENT X Y) (CONS (REMAINDER X Y) NIL)))) + (LAMBDA (X Y) (CONS (QUOTIENT X Y) (CONS (REMAINDER X Y) (QUOTE NIL))))) (DOC 32767 SUBR (BEOWULF HOST DOC)) (EFFACE 32767 @@ -78,8 +78,8 @@ (LAMBDA (X L) (COND - ((NULL L) NIL) - ((EQUAL X (CAR L)) (CDR L)) (T (RPLACD L (EFFACE X (CDR L))))))) + ((NULL L) (QUOTE NIL)) + ((EQUAL X (CAR L)) (CDR L)) ((QUOTE T) (RPLACD L (EFFACE X (CDR L))))))) (ERROR 32767 SUBR (BEOWULF HOST ERROR)) (EQ 32767 SUBR (BEOWULF HOST EQ)) (EQUAL 32767 SUBR (BEOWULF HOST EQUAL)) @@ -91,12 +91,12 @@ (GENSYM 32767 SUBR (BEOWULF HOST GENSYM)) (GET 32767 -;; EXPR -;; (LAMBDA -;; (X Y) -;; (COND -;; ((NULL X) NIL) -;; ((EQ (CAR X) Y) (CAR (CDR X))) (T (GET (CDR X) Y)))) + EXPR + (LAMBDA + (X Y) + (COND + ((NULL X) (QUOTE NIL)) + ((EQ (CAR X) Y) (CAR (CDR X))) ((QUOTE T) (GET (CDR X) Y)))) SUBR (BEOWULF HOST GET)) (GREATERP 32767 SUBR (BEOWULF HOST GREATERP)) (INTEROP 32767 SUBR (BEOWULF INTEROP INTEROP)) @@ -106,15 +106,15 @@ (LAMBDA (X Y) (COND - ((NULL X) NIL) + ((NULL X) (QUOTE NIL)) ((MEMBER (CAR X) Y) (CONS (CAR X) (INTERSECTION (CDR X) Y))) - (T (INTERSECTION (CDR X) Y))))) + ((QUOTE T) (INTERSECTION (CDR X) Y))))) (LENGTH 32767 EXPR (LAMBDA (L) - (COND ((EQ NIL L) 0) ((CONSP (CDR L)) (ADD1 (LENGTH (CDR L)))) (T 1)))) + (COND ((EQ NIL L) 0) ((CONSP (CDR L)) (ADD1 (LENGTH (CDR L)))) (T 0)))) (LESSP 32767 SUBR (BEOWULF HOST LESSP)) (MAPLIST 32767 @@ -122,7 +122,7 @@ (LAMBDA (L F) (COND - ((NULL L) NIL) (T (CONS (F (CAR L)) (MAPLIST (CDR L) F)))))) + ((NULL L) NIL) ((QUOTE T) (CONS (F (CAR L)) (MAPLIST (CDR L) F)))))) (MEMBER 32767 EXPR @@ -130,15 +130,14 @@ (A X) (COND ((NULL X) (QUOTE F)) - ((EQ A (CAR X)) T) (T (MEMBER A (CDR X)))))) + ((EQ A (CAR X)) (QUOTE T)) ((QUOTE T) (MEMBER A (CDR X)))))) (MINUSP 32767 EXPR (LAMBDA (X) (LESSP X 0))) - (NOT 32767 EXPR (LAMBDA (X) (COND (X NIL) (T T)))) + (NOT 32767 EXPR (LAMBDA (X) (COND (X (QUOTE NIL)) ((QUOTE T) (QUOTE T))))) (NULL - 32767 EXPR (LAMBDA (X) (COND ((EQUAL X NIL) T) (T (QUOTE F))))) + 32767 EXPR (LAMBDA (X) (COND ((EQUAL X NIL) (QUOTE T)) (T (QUOTE F))))) (NUMBERP 32767 SUBR (BEOWULF HOST NUMBERP)) (OBLIST 32767 SUBR (BEOWULF HOST OBLIST)) (ONEP 32767 EXPR (LAMBDA (X) (EQ X 1))) - (OR 32767 SUBR (BEOWULF HOST OR)) (PAIR 32767 EXPR @@ -156,12 +155,11 @@ (X Y A) (COND ((NULL X) A) - (T (CONS (CONS (CAR X) (CAR Y)) (PAIRLIS (CDR X) (CDR Y) A))))) + ((QUOTE T) (CONS (CONS (CAR X) (CAR Y)) (PAIRLIS (CDR X) (CDR Y) A))))) SUBR (BEOWULF HOST PAIRLIS)) (PLUS 32767 SUBR (BEOWULF HOST PLUS)) (PRETTY 32767) (PRINT 32767) - (PROG 32767 FSUBR (BEOWULF HOST PROG)) (PROP 32767 EXPR @@ -169,7 +167,7 @@ (X Y U) (COND ((NULL X) (U)) - ((EQ (CAR X) Y) (CDR X)) (T (PROP (CDR X) Y U))))) + ((EQ (CAR X) Y) (CDR X)) ((QUOTE T) (PROP (CDR X) Y U))))) (QUOTE 32767 EXPR (LAMBDA (X) X)) (QUOTIENT 32767 SUBR (BEOWULF HOST QUOTIENT)) (RANGE @@ -178,7 +176,7 @@ (LAMBDA (N M) (COND - ((LESSP M N) NIL) (T (CONS N (RANGE (ADD1 N) M)))))) + ((LESSP M N) (QUOTE NIL)) ((QUOTE T) (CONS N (RANGE (ADD1 N) M)))))) (READ 32767 SUBR (BEOWULF READ READ)) (REMAINDER 32767 SUBR (BEOWULF HOST REMAINDER)) (REPEAT @@ -187,11 +185,6 @@ (LAMBDA (N X) (COND ((EQ N 0) NIL) (T (CONS X (REPEAT (SUB1 N) X)))))) (RPLACA 32767 SUBR (BEOWULF HOST RPLACA)) (RPLACD 32767 SUBR (BEOWULF HOST RPLACD)) - (SEARCH 32767 EXPR - (LAMBDA (X P F U) - (COND ((NULL X) (U X)) - ((P X) (F X)) - ((QUOTE T) (SEARCH (CDR X) P F U))))) (SET 32767 SUBR (BEOWULF HOST SET)) (SUB1 32767 EXPR (LAMBDA (N) (DIFFERENCE N 1)) SUBR (BEOWULF HOST SUB1)) (SUB2 @@ -200,19 +193,9 @@ (LAMBDA (A Z) (COND - ((NULL A) Z) ((EQ (CAAR A) Z) (CDAR A)) (T (SUB2 (CDAR A) Z))))) + ((NULL A) Z) ((EQ (CAAR A) Z) (CDAR A)) ((QUOTE T) (SUB2 (CDAR A) Z))))) (SUBLIS - 32767 EXPR - (LAMBDA (X Y) - (COND ((NULL X) Y) - ((NULL Y) Y) - ((QUOTE T) (SEARCH X - (LAMBDA (J) (EQUAL Y (CAAR J))) - (LAMBDA (J) (CDAR J)) - (LAMBDA (J) (COND ((ATOM Y) Y) - ((QUOTE T) (CONS - (SUBLIS X (CAR Y)) - (SUBLIS X (CDR Y))))))))))) + 32767 EXPR (LAMBDA (A Y) (COND ((ATOM Y) (SUB2 A Y)) ((QUOTE T) (CONS))))) (SUBST 32767 EXPR @@ -221,7 +204,7 @@ (COND ((EQUAL Y Z) X) ((ATOM Z) Z) - (T (CONS (SUBST X Y (CAR Z)) (SUBST X Y (CDR Z))))))) + ((QUOTE T) (CONS (SUBST X Y (CAR Z)) (SUBST X Y (CDR Z))))))) (SYSIN 32767 SUBR (BEOWULF IO SYSIN)) (SYSOUT 32767 SUBR (BEOWULF IO SYSOUT)) (TERPRI 32767) diff --git a/resources/mexpr/not.mexpr b/resources/mexpr/not.mexpr deleted file mode 100644 index 4aa5b5b..0000000 --- a/resources/mexpr/not.mexpr +++ /dev/null @@ -1 +0,0 @@ -not[x] = [x = F -> T; x = NIL -> T; T -> F] \ No newline at end of file diff --git a/resources/mexpr/search.mexpr.lsp b/resources/mexpr/search.mexpr.lsp deleted file mode 100644 index bba53c6..0000000 --- a/resources/mexpr/search.mexpr.lsp +++ /dev/null @@ -1,5 +0,0 @@ -# page 63 - -search[x; p; f; u] = [null[x] -> u[x]; - p[x] -> f[x]; - T -> search[cdr[x]; p; f; u]] \ No newline at end of file diff --git a/resources/mexpr/sublis.mexpr.lsp b/resources/mexpr/sublis.mexpr.lsp index f17b5f8..d9c3797 100644 --- a/resources/mexpr/sublis.mexpr.lsp +++ b/resources/mexpr/sublis.mexpr.lsp @@ -7,19 +7,4 @@ sub2[a; z] = [null[a] -> z; T -> sub2[cdar[a]; z]] sublis[a; y] = [atom[y] -> sub2[a; y]; - T -> cons[sublis[a; car[y]]; - sublis[a; cdr[y]]]] - -;; this is the version from page 61 - -sublis[x;y] = [null[x] -> y; - null[y] -> y; - T -> search[x; - λ[[j]; equal[y; caar[j]]]; - λ[[j]; cdar[j]]; - λ[[j]; [atom[y] -> y; - T -> cons[sublis[x; car[y]]; - sublis[x; cdr[y]]]]]]] - -;; the test for this is: -;; (SUBLIS '((X . SHAKESPEARE) (Y . (THE TEMPEST))) '(X WROTE Y)) \ No newline at end of file + T -> cons[]] \ No newline at end of file diff --git a/src/beowulf/bootstrap.clj b/src/beowulf/bootstrap.clj index d530f62..9637a69 100644 --- a/src/beowulf/bootstrap.clj +++ b/src/beowulf/bootstrap.clj @@ -9,8 +9,7 @@ ALLUPPERCASE are Lisp 1.5 functions (although written in Clojure) and that therefore all arguments must be numbers, symbols or `beowulf.cons_cell.ConsCell` objects." - (:require [beowulf.cons-cell :refer [F make-beowulf-list make-cons-cell - pretty-print T]] + (:require [beowulf.cons-cell :refer [make-beowulf-list make-cons-cell T]] [beowulf.host :refer [ASSOC ATOM CAAR CADAR CADDR CADR CAR CDR GET LIST NUMBERP PAIRLIS traced?]] [beowulf.oblist :refer [*options* NIL oblist]]) @@ -37,169 +36,20 @@ ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(declare APPLY EVAL prog-eval) +(declare APPLY EVAL) -;;;; The PROGram feature ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(def find-target - (memoize - (fn [target body] - (loop [body' body] - (cond - (= body' NIL) (throw (ex-info (str "Mislar GO miercels: `" target "`") - {:phase :lisp - :function 'PROG - :type :lisp - :code :A6 - :target target})) - (= (.getCar body') target) body' - :else (recur (.getCdr body'))))))) - -(defn- prog-cond - "Like `EVCON`, q.v. except using `prog-eval` instead of `EVAL` and not - throwing an error if no clause matches." - [clauses vars env depth] - (loop [clauses' clauses] - (if-not (= clauses' NIL) - (let [test (prog-eval (CAAR clauses') vars env depth)] - (if (not (#{NIL F} test)) - (prog-eval (CADAR clauses') vars env depth) - (recur (.getCdr clauses')))) - NIL))) - -(defn- merge-vars [vars env] - (reduce - #(make-cons-cell - (make-cons-cell %2 (@vars %2)) - env) - env - (keys @vars))) - -(defn prog-eval - "Like `EVAL`, q.v., except handling symbols, and expressions starting - `GO`, `RETURN`, `SET` and `SETQ` specially." - [expr vars env depth] - (cond - (number? expr) expr - (symbol? expr) (@vars expr) - (instance? ConsCell expr) (case (.getCar expr) - COND (prog-cond (.getCdr expr) - vars env depth) - GO (make-cons-cell - '*PROGGO* (.getCar (.getCdr expr))) - RETURN (make-cons-cell - '*PROGRETURN* - (prog-eval (.getCar (.getCdr expr)) - vars env depth)) - SET (let [v (CADDR expr)] - (swap! vars - assoc - (prog-eval (CADR expr) - vars env depth) - (prog-eval (CADDR expr) - vars env depth)) - v) - SETQ (let [v (CADDR expr)] - (swap! vars - assoc - (CADR expr) - (prog-eval v - vars env depth)) - v) - ;; else - (beowulf.bootstrap/EVAL expr - (merge-vars vars env) - depth)))) - -(defn PROG - "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." - [program env depth] - (let [trace (traced? 'PROG) - vars (atom (reduce merge (map #(assoc {} % NIL) (.getCar program)))) - body (.getCdr program) - targets (set (filter symbol? body))] - (when trace (do - (println "Program:") - (pretty-print program))) ;; for debugging - (loop [cursor body] - (let [step (.getCar cursor)] - (when trace (do (println "Executing step: " step) - (println " with vars: " @vars))) - (cond (= cursor NIL) NIL - (symbol? step) (recur (.getCdr cursor)) - :else (let [v (prog-eval (.getCar cursor) vars env depth)] - (when trace (println " --> " v)) - (if (instance? ConsCell v) - (case (.getCar v) - *PROGGO* (let [target (.getCdr v)] - (if (targets target) - (recur (find-target target body)) - (throw (ex-info (str "Uncynlic GO miercels `" - target "`") - {:phase :lisp - :function 'PROG - :args program - :type :lisp - :code :A6 - :target target - :targets targets})))) - *PROGRETURN* (.getCdr v) - ;; else - (recur (.getCdr cursor))) - (recur (.getCdr cursor))))))))) - -;;;; Tracing execution ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defn try-resolve-subroutine + "Attempt to resolve this `subr` with these `arg`." + [subr args] + (when (and subr (not= subr NIL)) + (try @(resolve subr) + (catch Throwable any + (throw (ex-info "Failed to resolve subroutine" + {:phase :apply + :function subr + :args args + :type :beowulf} + any)))))) (defn- trace-call "Show a trace of a call to the function named by this `function-symbol` @@ -228,46 +78,21 @@ (first (remove #(= % NIL) (map #(GET s %) indicators)))))) -;;;; APPLY ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defn try-resolve-subroutine - "Attempt to resolve this `subr` with these `args`." - [subr args] - (when (and subr (not= subr NIL)) - (try @(resolve subr) - (catch Throwable any - (throw (ex-info "þegnung (SUBR) ne āfand" - {:phase :apply - :function subr - :args args - :type :beowulf} - any)))))) - (defn- apply-symbolic "Apply this `funtion-symbol` to these `args` in this `environment` and return the result." [^Symbol function-symbol args ^ConsCell environment depth] (trace-call function-symbol args depth) - (let [lisp-fn (value function-symbol '(EXPR FEXPR)) - args' (cond (= NIL args) args - (empty? args) NIL - (instance? ConsCell args) args - :else (make-beowulf-list args)) + (let [lisp-fn ;; (try + (value function-symbol '(EXPR FEXPR)) + ;; (catch Exception any (when (traced? function-symbol) + ;; (println any)))) subr (value function-symbol '(SUBR FSUBR)) - host-fn (try-resolve-subroutine subr args') + host-fn (try-resolve-subroutine subr args) result (cond (and lisp-fn - (not= lisp-fn NIL)) (APPLY lisp-fn args' environment depth) - host-fn (try - (apply host-fn (when (instance? ConsCell args') args')) - (catch Exception any - (throw (ex-info (str "Uncynlic þegnung: " - (.getMessage any)) - {:phase :apply - :function function-symbol - :args args - :type :beowulf} - any)))) - :else (ex-info "þegnung ne āfand" + (not= lisp-fn NIL)) (APPLY lisp-fn args environment depth) + host-fn (apply host-fn (when (instance? ConsCell args) args)) + :else (ex-info "No function found" {:phase :apply :function function-symbol :args args @@ -287,7 +112,7 @@ (let [result (cond (= NIL function) (if (:strict *options*) NIL - (throw (ex-info "NIL sí ne þegnung" + (throw (ex-info "NIL is not a function" {:phase :apply :function "NIL" :args args @@ -307,7 +132,7 @@ LAMBDA (EVAL (CADDR function) (PAIRLIS (CADR function) args environment) depth) - (throw (ex-info "Ungecnáwen wyrþan sí þegnung-weard" + (throw (ex-info "Unrecognised value in function position" {:phase :apply :function function :args args @@ -315,31 +140,18 @@ (trace-response 'APPLY result depth) result)) -;;;; EVAL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - (defn- EVCON "Inner guts of primitive COND. All `clauses` are assumed to be `beowulf.cons-cell/ConsCell` objects. Note that tests in Lisp 1.5 - often return `F`, not `NIL`, on failure. If no clause matches, - then, strictly, we throw an error with code `:A3`. + often return `F`, not `NIL`, on failure. - See pages 13 and 71 of the Lisp 1.5 Programmers Manual." + See page 13 of the Lisp 1.5 Programmers Manual." [clauses env depth] - (loop [clauses' clauses] - (if-not (= clauses' NIL) - (let [test (EVAL (CAAR clauses') env depth)] - (if (not (#{NIL F} test)) - ;; (and (not= test NIL) (not= test F)) - (EVAL (CADAR clauses') env depth) - (recur (.getCdr clauses')))) - (if (:strict *options*) - (throw (ex-info "Ne ġefōg dǣl in COND" - {:phase :eval - :function 'COND - :args (list clauses) - :type :lisp - :code :A3})) - NIL)))) + (let [test (EVAL (CAAR clauses) env depth)] + (if + (and (not= test NIL) (not= test 'F)) + (EVAL (CADAR clauses) env depth) + (EVCON (CDR clauses) env depth)))) (defn- EVLIS "Map `EVAL` across this list of `args` in the context of this @@ -355,18 +167,18 @@ (defn- eval-symbolic [expr env depth] - (let [v (ASSOC expr env) + (let [v (value expr (list 'APVAL)) indent (apply str (repeat depth "-"))] (when (traced? 'EVAL) - (println (str indent ": EVAL: sceald bindele: " (or v "nil")))) - (if (instance? ConsCell v) - (.getCdr v) - (let [v' (value expr (list 'APVAL))] + (println (str indent ": EVAL: deep binding (" expr " . " (or v "nil") ")"))) + (if (and v (not= v NIL)) + v + (let [v' (ASSOC expr env)] (when (traced? 'EVAL) - (println (str indent ": EVAL: deóp bindele: (" expr " . " (or v' "nil") ")"))) - (if v' - v' - (throw (ex-info "Ne tácen-bindele āfand" + (println (str indent ": EVAL: shallow binding: " (or v' "nil")))) + (if (and v' (not= v' NIL)) + (.getCdr v') + (throw (ex-info "No binding for symbol found" {:phase :eval :function 'EVAL :args (list expr env depth) @@ -385,12 +197,10 @@ (let [expr' (if (and (coll? expr) (not (instance? ConsCell expr))) (make-beowulf-list expr) expr)] - (EVAL expr' NIL 0))) + (EVAL expr' @oblist 0))) ([expr env depth] (trace-call 'EVAL (list expr env depth) depth) (let [result (cond - (= NIL expr) NIL ;; it was probably a mistake to make Lisp - ;; NIL distinct from Clojure nil (= (NUMBERP expr) T) expr (symbol? expr) (eval-symbolic expr env depth) (string? expr) (if (:strict *options*) @@ -402,10 +212,9 @@ :expr expr})) (symbol expr)) (= (ATOM (CAR expr)) T) (case (CAR expr) - COND (EVCON (CDR expr) env depth) - FUNCTION (LIST 'FUNARG (CADR expr)) - PROG (PROG (CDR expr) env depth) QUOTE (CADR expr) + FUNCTION (LIST 'FUNARG (CADR expr)) + COND (EVCON (CDR expr) env depth) ;; else (APPLY (CAR expr) diff --git a/src/beowulf/cons_cell.clj b/src/beowulf/cons_cell.clj index fb24730..e1a7f52 100644 --- a/src/beowulf/cons_cell.clj +++ b/src/beowulf/cons_cell.clj @@ -77,7 +77,7 @@ (set! (. this CAR) value) this) (throw (ex-info - (str "Uncynlic miercels in RPLACA: `" value "` (" (type value) ")") + (str "Invalid value in RPLACA: `" value "` (" (type value) ")") {:cause :bad-value :detail :rplaca})))) @@ -92,7 +92,7 @@ (set! (. this CDR) value) this) (throw (ex-info - (str "Uncynlic miercels in RPLACD: `" value "` (" (type value) ")") + (str "Invalid value in RPLACD: `" value "` (" (type value) ")") {:cause :bad-value :detail :rplaca})))) @@ -248,7 +248,7 @@ (try (ConsCell. car cdr (gensym "c")) (catch Exception any - (throw (ex-info "Ne meahte cræfte cons cell" {:car car + (throw (ex-info "Cound not construct cons cell" {:car car :cdr cdr} any))))) (defn make-beowulf-list @@ -269,6 +269,6 @@ :else NIL) (catch Exception any - (throw (ex-info "Ne meahte cræfte Beowulf líste" + (throw (ex-info "Could not construct Beowulf list" {:content x} any))))) diff --git a/src/beowulf/core.clj b/src/beowulf/core.clj index d20339d..99b5a59 100644 --- a/src/beowulf/core.clj +++ b/src/beowulf/core.clj @@ -30,10 +30,7 @@ ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(def stop-word - "The word which, if submitted an an input line, will cause Beowulf to quit. - Question: should this be `forlǣte`?" - "STOP") +(def stop-word "STOP") (def cli-options [["-f FILEPATH" "--file-path FILEPATH" @@ -46,12 +43,12 @@ ["-h" "--help"] ["-p PROMPT" "--prompt PROMPT" "Set the REPL prompt to PROMPT" :default "Sprecan::"] - ["-r SYSOUTFILE" "--read SYSOUTFILE" "Read Lisp system from file SYSOUTFILE" + ["-r INITFILE" "--read INITFILE" "Read Lisp system from file INITFILE" :default default-sysout :validate [#(and (.exists (io/file %)) (.canRead (io/file %))) - "Could not find sysout file"]] + "Could not find initfile"]] ["-s" "--strict" "Strictly interpret the Lisp 1.5 language, without extensions."] ["-t" "--time" "Time evaluations."]]) @@ -127,6 +124,6 @@ :quit nil ;; default (do - (println "STÆFLEAHTER: " (.getMessage e)) + (println "ERROR: " (.getMessage e)) (pprint data))) (println e)))))))) diff --git a/src/beowulf/gendoc.clj b/src/beowulf/gendoc.clj index 8204ede..994549e 100644 --- a/src/beowulf/gendoc.clj +++ b/src/beowulf/gendoc.clj @@ -8,7 +8,7 @@ *manual-url* page-url]] [beowulf.oblist :refer [NIL oblist]] [clojure.java.browse :refer [browse-url]] - [clojure.string :as s])) + [clojure.string :as s ])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -60,6 +60,7 @@ (when (keyword? key) (key (get-metadata-for-function function))))) + (defn- get-metadata-for-entry [entry key] (let [fn ((host-functions) (symbol (first entry)))] (get-metadata-for-function fn key))) @@ -68,25 +69,13 @@ "Try to work out what this `entry` from the oblist actually represents." [entry] - (let [interpretation {'APVAL "Lisp variable" - 'EXPR "Lisp lambda function" - 'FEXPR "Lisp nlambda function" - 'SUBR "Host lambda function" - 'FSUBR "Host nlambda function"}] - (s/join ", " - (remove nil? - (map - #(when (some #{%} entry) (interpretation %)) - (keys interpretation)))))) - ;; (cond - ;; (= (nth entry 2) 'EXPR) "Lisp function" - ;; (= (nth entry 2) 'FEXPR) "Labeled form" - ;; ((host-functions) (first entry)) (try (if (fn? (eval (symbol ((host-functions) (first entry))))) - ;; "Host function" - ;; "Host variable") - ;; (catch Exception _ - ;; "?Host macro?")) - ;; :else "Lisp variable")) + (cond + (= (second entry) 'LAMBDA) "Lisp function" + (= (second entry) 'LABEL) "Labeled form" + ((host-functions) (first entry)) (if (fn? (eval (symbol ((host-functions) (first entry))))) + "Host function" + "Host variable") + :else "Lisp variable")) (defn- format-clj-signature "Format the signature of the Clojure function represented by `symbol` for @@ -98,7 +87,7 @@ (map (fn [l] (s/join (concat (list "(" symbol " ") - (s/join " " (map #(s/upper-case (str %)) l)) (list ")")))) + (s/join " " (map #(s/upper-case (str %)) l)) (list ")")))) arglists)))) (defn infer-signature @@ -113,18 +102,17 @@ (defn infer-implementation [entry] - (or (:implementation (index (keyword (first entry)))) "?")) - ;; (case (second entry) - ;; LAMBDA (format "%s-fn" (second entry)) - ;; LABEL (format "%s-fn" (second entry)) - ;; (or (:implementation (index (keyword (first entry)))) (str entry)))) + (case (second entry) + LAMBDA (format "%s-fn" (second entry)) + LABEL (format "%s-fn" (second entry)) + (or (:implementation (index (keyword (first entry)))) (str entry)))) (defn find-documentation "Find appropriate documentation for this `entry` from the oblist." [entry] (let [k (keyword (first entry))] (cond - (some #{'SUBR 'FSUBR} entry) (if-let [doc (get-metadata-for-entry entry :doc)] + (= (count entry) 1) (if-let [doc (get-metadata-for-entry entry :doc)] (s/replace doc "\n" " ") "?") (k index) (str "see manual pages " (format-page-references k)) @@ -171,12 +159,12 @@ web browser." [symbol] (let [doc (get-metadata-for-function symbol :doc)] - (if-let [pages (:page-nos (index (keyword symbol)))] - (browse-url (page-url (first pages))) - (if doc - (println doc) - (throw (ex-info "No documentation found" - {:phase :host - :function 'DOC - :args (list symbol) - :type :beowulf})))))) \ No newline at end of file + (if-let [pages (:page-nos (index (keyword symbol)))] + (browse-url (page-url (first pages))) + (if doc + (println doc) + (throw (ex-info "No documentation found" + {:phase :host + :function 'DOC + :args (list symbol) + :type :beowulf})))))) \ No newline at end of file diff --git a/src/beowulf/host.clj b/src/beowulf/host.clj index 48f622d..82821ce 100644 --- a/src/beowulf/host.clj +++ b/src/beowulf/host.clj @@ -2,8 +2,7 @@ "provides Lisp 1.5 functions which can't be (or can't efficiently be) implemented in Lisp 1.5, which therefore need to be implemented in the host language, in this case Clojure." - (:require [beowulf.cons-cell :refer [F make-beowulf-list make-cons-cell - pretty-print T]] ;; note hyphen - this is Clojure... + (:require [beowulf.cons-cell :refer [F make-beowulf-list make-cons-cell T]] ;; note hyphen - this is Clojure... [beowulf.gendoc :refer [open-doc]] [beowulf.oblist :refer [*options* NIL oblist]] [clojure.set :refer [union]] @@ -41,7 +40,7 @@ this `symbol`." [symbol] (when (:strict *options*) - (throw (ex-info (format "%s ne āfand innan Lisp 1.5" symbol) + (throw (ex-info (format "%s is not available in Lisp 1.5" symbol) {:type :strict :phase :host :function symbol}))) @@ -58,30 +57,41 @@ "Return the item indicated by the first pointer of a pair. NIL is treated specially: the CAR of NIL is NIL." [x] - (cond - (= x NIL) NIL - (instance? ConsCell x) (or (.getCar x) NIL) - :else (throw (ex-info - (str "Ne can tace CAR of `" x "` (" (.getName (.getClass x)) ")") - {:phase :host - :function 'CAR - :args (list x) - :type :beowulf})))) + (if + (= x NIL) NIL + (try + (or (.getCar x) NIL) + (catch Exception any + (throw (ex-info + (str "Cannot take CAR of `" x "` (" (.getName (.getClass x)) ")") + {:phase :host + :function 'CAR + :args (list x) + :type :beowulf} + ;; startlingly, Lisp 1.5 did not flag an error when you took the + ;; CAR of something that wasn't cons cell. The result, as the + ;; manual says (page 56), could be garbage. + any)))))) (defn CDR "Return the item indicated by the second pointer of a pair. NIL is treated specially: the CDR of NIL is NIL." [x] - (cond - (= x NIL) NIL - (instance? ConsCell x) (or (.getCdr x) NIL) - :else (throw (ex-info - (str "Ne can tace CDR of `" x "` (" (.getName (.getClass x)) ")") - {:phase :host - :function 'CDR - :args (list x) - :type :beowulf})))) - + (if + (= x NIL) NIL + (try + (.getCdr x) + (catch Exception any + (throw (ex-info + (str "Cannot take CDR of `" x "` (" (.getName (.getClass x)) ")") + {:phase :host + :function 'CDR + :args (list x) + :type :beowulf} + ;; startlingly, Lisp 1.5 did not flag an error when you took the + ;; CAR of something that wasn't cons cell. The result, as the + ;; manual says (page 56), could be garbage. + any)))))) (defn uaf "Universal access function; `l` is expected to be an arbitrary LISP list, `path` @@ -165,14 +175,14 @@ :type :beowulf} any)))) (throw (ex-info - (str "Un-ġefōg þing in RPLACA: `" value "` (" (type value) ")") + (str "Invalid value in RPLACA: `" value "` (" (type value) ")") {:cause :bad-value :phase :host :function :rplaca :args (list cell value) :type :beowulf}))) (throw (ex-info - (str "Uncynlic miercels in RPLACA: `" cell "` (" (type cell) ")") + (str "Invalid cell in RPLACA: `" cell "` (" (type cell) ")") {:cause :bad-cell :phase :host :function :rplaca @@ -205,14 +215,14 @@ :type :beowulf} any)))) (throw (ex-info - (str "Un-ġefōg þing in RPLACD: `" value "` (" (type value) ")") + (str "Invalid value in RPLACD: `" value "` (" (type value) ")") {:cause :bad-value :phase :host :function :rplacd :args (list cell value) :type :beowulf}))) (throw (ex-info - (str "Uncynlic miercels in RPLACD: `" cell "` (" (type cell) ")") + (str "Invalid cell in RPLACD: `" cell "` (" (type cell) ")") {:cause :bad-cell :phase :host :detail :rplacd @@ -278,13 +288,10 @@ In `beowulf.host` principally because I don't yet feel confident to define varargs functions in Lisp." [& args] - ;; (println "AND: " args " type: " (type args) " seq? " (seq? args)) - ;; (println " filtered: " (seq (filter #{F NIL} args))) (cond (= NIL args) T - (seq? args) (if (seq (filter #{F NIL} args)) F T) + (not (#{NIL F} (.getCar args))) (AND (.getCdr args)) :else T)) - (defn OR "`T` if and only if at least one of my `args` evaluates to something other than either `F` or `NIL`, else `F`. @@ -292,12 +299,9 @@ In `beowulf.host` principally because I don't yet feel confident to define varargs functions in Lisp." [& args] - ;; (println "OR: " args " type: " (type args) " seq? " (seq? args)) - ;; (println " filtered: " (seq (remove #{F NIL} args))) (cond (= NIL args) F - (seq? args) (if (seq (remove #{F NIL} args)) T F) - :else F)) - + (not (#{NIL F} (.getCar args))) T + :else (OR (.getCdr args)))) ;;;; Operations on lists ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; @@ -410,11 +414,11 @@ (defn ERROR "Throw an error" [& args] - (throw (ex-info "LISP STÆFLEAHTER" {:args args - :phase :eval - :function 'ERROR - :type :lisp - :code (or (first args) 'A1)}))) + (throw (ex-info "LISP ERROR" {:args args + :phase :eval + :function 'ERROR + :type :lisp + :code (or (first args) 'A1)}))) ;;;; Assignment and the object list ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -473,26 +477,19 @@ 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." [symbol indicator] - (let [binding (ASSOC symbol @oblist) - val (cond - (= binding NIL) NIL - (= magic-marker - (CADR binding)) (loop [b binding] - ;; (println "GET loop, seeking " indicator ":") - ;; (pretty-print b) - (if (instance? ConsCell b) - (if (= (CAR b) indicator) - (CADR b) ;; <- this is what we should actually be returning - (recur (CDR b))) - NIL)) - :else (throw - (ex-info "Misformatted property list (missing magic marker)" - {:phase :host - :function :get - :args (list symbol indicator) - :type :beowulf})))] - ;; (println "<< GET returning: " val) - val)) + (let [binding (ASSOC symbol @oblist)] + (cond + (= binding NIL) NIL + (= magic-marker (CADR binding)) (loop [b binding] + (cond (= b NIL) NIL + (= (CAR b) indicator) (CADR b) + :else (recur (CDR b)))) + :else (throw + (ex-info "Misformatted property list (missing magic marker)" + {:phase :host + :function :get + :args (list symbol indicator) + :type :beowulf}))))) (defn DEFLIST "For each pair in this association list `a-list`, set the property with this @@ -568,4 +565,4 @@ argument was, or was not, a cons cell." [o] (when (lax? 'CONSP) - (if (instance? ConsCell o) 'T 'F))) \ No newline at end of file + (if (instance? o ConsCell) 'T 'F))) \ No newline at end of file diff --git a/src/beowulf/interop.clj b/src/beowulf/interop.clj index d4569fa..b993fbe 100644 --- a/src/beowulf/interop.clj +++ b/src/beowulf/interop.clj @@ -100,16 +100,16 @@ (catch java.lang.ClassNotFoundException _ nil)) q-name :else (throw (ex-info - (str "INTEROP: ungecnáwen þegnung `" fn-symbol "`") + (str "INTEROP: unknown function `" fn-symbol "`") {:cause :interop :detail :not-found :name fn-symbol :also-tried l-name}))) args' (to-clojure args)] -;; (print (str "INTEROP: eahtiende `" (cons f args') "`")) + (print (str "INTEROP: evaluating `" (cons f args') "`")) (flush) (let [result (eval (conj args' f))] ;; this has the potential to blow up the world -;; (println (str "; ágiefende `" result "`")) + (println (str "; returning `" result "`")) (cond (instance? beowulf.cons_cell.ConsCell result) result (coll? result) (make-beowulf-list result) @@ -118,12 +118,12 @@ (number? result) result :else (throw (ex-info - (str "INTEROP: Ne can eahtiende `" result "` to Lisp 1.5.") + (str "INTEROP: Cannot return `" result "` to Lisp 1.5.") {:cause :interop :detail :not-representable :result result}))))) (throw (ex-info - (str "INTEROP ne āfand innan Lisp 1.5.") + (str "INTEROP not allowed in strict mode.") {:cause :interop :detail :strict})))) diff --git a/src/beowulf/io.clj b/src/beowulf/io.clj index 62ead4c..b97d8c7 100644 --- a/src/beowulf/io.clj +++ b/src/beowulf/io.clj @@ -46,7 +46,7 @@ ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(def ^:constant default-sysout "lisp1.5.lsp") +(def ^:constant default-sysout "resources/lisp1.5.lsp") (defn- full-path [fp] @@ -105,15 +105,12 @@ (pretty-print output) ))))) -(defn resolve-subr +(defn- resolve-subr "If this oblist `entry` references a subroutine, attempt to fix up that reference." - ([entry] - (or (resolve-subr entry 'SUBR) - (resolve-subr entry 'FSUBR))) - ([entry prop] - (cond (= entry NIL) NIL - (= (CAR entry) prop) (try + [entry] + (cond (= entry NIL) NIL + (= (CAR entry) 'SUBR) (try (make-cons-cell (CAR entry) (make-cons-cell @@ -121,11 +118,11 @@ (CADR entry)) (CDDR entry))) (catch Exception _ - (print "Warnung: ne can āfinde " + (print "Warning: failed to resolve " (CADR entry)) (CDDR entry))) :else (make-cons-cell - (CAR entry) (resolve-subr (CDR entry)))))) + (CAR entry) (resolve-subr (CDR entry))))) (defn- resolve-subroutines @@ -154,18 +151,18 @@ **NOTE THAT** this is an extension function, not available in strct mode." ([] - (SYSIN (or (:read *options*) (str "resources/" default-sysout)))) + (SYSIN (or (:read *options*) default-sysout))) ([filename] (let [fp (file (full-path (str filename))) file (when (and (.exists fp) (.canRead fp)) fp) res (try (resource filename) (catch Throwable _ nil)) content (try (READ (slurp (or file res))) - (catch Throwable _ - (throw (ex-info "Ne can ārǣde" + (catch Throwable any + (throw (ex-info "Could not read from file" {:context "SYSIN" - :filename filename - :filepath fp}))))] + :filepath fp} + any))))] (swap! oblist #(when (or % (seq content)) (resolve-subroutines content)))))) diff --git a/src/beowulf/read.clj b/src/beowulf/read.clj index 54fcfe4..39abf1d 100644 --- a/src/beowulf/read.clj +++ b/src/beowulf/read.clj @@ -13,7 +13,7 @@ Both these extensions can be disabled by using the `--strict` command line switch." - (:require ;; [beowulf.reader.char-reader :refer [read-chars]] + (:require [beowulf.reader.char-reader :refer [read-chars]] [beowulf.reader.generate :refer [generate]] [beowulf.reader.parser :refer [parse]] [beowulf.reader.simplify :refer [simplify]] @@ -79,7 +79,7 @@ parse-tree (parse source)] (if (instance? Failure parse-tree) (doall (println (number-lines source parse-tree)) - (throw (ex-info "Ne can forstande " (assoc parse-tree :source source)))) + (throw (ex-info "Parse failed" (assoc parse-tree :source source)))) (generate (simplify parse-tree))))) (defn read-from-console @@ -99,7 +99,7 @@ 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." ([] - (gsp (read-from-console))) + (gsp (read-chars))) ([input] (cond (empty? input) (READ) diff --git a/src/beowulf/reader/char_reader.clj b/src/beowulf/reader/char_reader.clj index 883f8fa..46f28d1 100644 --- a/src/beowulf/reader/char_reader.clj +++ b/src/beowulf/reader/char_reader.clj @@ -15,14 +15,9 @@ rather than the strings which were supplied to `READ`); 4. offers potential auto-completions taken from the value of `(OBLIST)`, ideally the current value, not the value at the time the session started; - 5. and offer movement and editing within the line. - - TODO: There are multiple problems with JLine; a better solution might be - to start from here: - https://stackoverflow.com/questions/7931988/how-to-manipulate-control-characters" - ;; (:import [org.jline.reader LineReader LineReaderBuilder] - ;; [org.jline.terminal TerminalBuilder]) - ) + 5. and offer movement and editing within the line." + (:import [org.jline.reader LineReader LineReaderBuilder] + [org.jline.terminal TerminalBuilder])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -49,27 +44,27 @@ ;; looks as though you'd need a DPhil in JLine to write it, and I don't have ;; the time. -;; (def get-reader -;; "Return a reader, first constructing it if necessary. +(def get-reader + "Return a reader, first constructing it if necessary. -;; **NOTE THAT** this is not settled API. The existence and call signature of -;; this function is not guaranteed in future versions." -;; (memoize (fn [] -;; (let [term (.build (.system (TerminalBuilder/builder) true))] -;; (.build (.terminal (LineReaderBuilder/builder) term)))))) + **NOTE THAT** this is not settled API. The existence and call signature of + this function is not guaranteed in future versions." + (memoize (fn [] + (let [term (.build (.system (TerminalBuilder/builder) true))] + (.build (.terminal (LineReaderBuilder/builder) term)))))) -;; (defn read-chars -;; "A drop-in replacement for `clojure.core/read-line`, except that line editing -;; and history should be enabled. +(defn read-chars + "A drop-in replacement for `clojure.core/read-line`, except that line editing + and history should be enabled. -;; **NOTE THAT** this does not work yet, but it is in the API because I hope -;; that it will work later!" -;; [] -;; (let [eddie (get-reader)] -;; (loop [s (.readLine eddie)] -;; (if (and (= (count (re-seq #"\(" s)) -;; (count (re-seq #"\)" s))) -;; (= (count (re-seq #"\[]" s)) -;; (count (re-seq #"\]" s)))) -;; s -;; (recur (str s " " (.readLine eddie))))))) \ No newline at end of file + **NOTE THAT** this does not work yet, but it is in the API because I hope + that it will work later!" + [] + (let [eddie (get-reader)] + (loop [s (.readLine eddie)] + (if (and (= (count (re-seq #"\(" s)) + (count (re-seq #"\)" s))) + (= (count (re-seq #"\[]" s)) + (count (re-seq #"\]" s)))) + s + (recur (str s " " (.readLine eddie))))))) \ No newline at end of file diff --git a/src/beowulf/reader/generate.clj b/src/beowulf/reader/generate.clj index 8d4edcc..2240d1f 100644 --- a/src/beowulf/reader/generate.clj +++ b/src/beowulf/reader/generate.clj @@ -59,8 +59,7 @@ [beowulf.reader.macros :refer [expand-macros]] [beowulf.oblist :refer [NIL]] [clojure.math.numeric-tower :refer [expt]] - [clojure.string :refer [upper-case]] - [clojure.tools.trace :refer [deftrace]])) + [clojure.string :refer [upper-case]])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -87,37 +86,37 @@ (defn gen-cond-clause "Generate a cond clause from this simplified parse tree fragment `p`; returns `nil` if `p` does not represent a cond clause." - [p context] + [p] (when (and (coll? p) (= :cond-clause (first p))) (make-beowulf-list (list (if (= (nth p 1) [:quoted-expr [:atom "T"]]) 'T - (generate (nth p 1) context)) - (generate (nth p 2) context))))) + (generate (nth p 1))) + (generate (nth p 2)))))) (defn gen-cond "Generate a cond statement from this simplified parse tree fragment `p`; returns `nil` if `p` does not represent a (MEXPR) cond statement." - [p context] + [p] (when (and (coll? p) (= :cond (first p))) (make-beowulf-list (cons 'COND (map - #(generate % (if (= context :mexpr) :cond-mexpr context)) + generate (rest p)))))) (defn gen-fn-call "Generate a function call from this simplified parse tree fragment `p`; returns `nil` if `p` does not represent a (MEXPR) function call." - [p context] + [p] (when (and (coll? p) (= :fncall (first p)) (= :mvar (first (second p)))) (make-cons-cell - (generate (second p) context) - (generate (nth p 2) context)))) + (generate (second p)) + (generate (nth p 2))))) (defn gen-dot-terminated-list @@ -138,50 +137,38 @@ (generate (first p)) (gen-dot-terminated-list (rest p))))) -;; null[x] = [x = NIL -> T; T -> F] -;; [:defn -;; [:mexpr [:fncall [:mvar "null"] [:bindings [:args [:mexpr [:mvar "x"]]]]]] -;; "=" -;; [:mexpr [:cond -;; [:cond-clause [:mexpr [:iexpr [:lhs [:mexpr [:mvar "x"]]] [:iop "="] [:rhs [:mexpr [:mconst "NIL"]]]]] [:mexpr [:mconst "T"]]] -;; [:cond-clause [:mexpr [:mconst "T"]] [:mexpr [:mconst "F"]]]]]] - (defn generate-defn - [tree context] - (if (= :mexpr (first tree)) - (generate-defn (second tree) context) - (make-beowulf-list - (list 'PUT - (list 'QUOTE (generate (-> tree second second second) context)) - (list 'QUOTE 'EXPR) - (list 'QUOTE - (cons 'LAMBDA - (list (generate (nth (-> tree second second) 2) context) - (generate (nth tree 3) context)))))))) + [tree] + (make-beowulf-list + (list 'SET + (list 'QUOTE (generate (-> tree second second))) + (list 'QUOTE + (cons 'LAMBDA + (cons (generate (nth (second tree) 2)) + (map generate (-> tree rest rest rest)))))))) (defn gen-iexpr - [tree context] - (let [bundle (reduce #(assoc %1 (first %2) %2) - {} + [tree] + (let [bundle (reduce #(assoc %1 (first %2) %2) + {} (rest tree))] - (list (generate (:iop bundle) context) - (generate (:lhs bundle) context) - (generate (:rhs bundle) context)))) + (list (generate (:iop bundle)) + (generate (:lhs bundle)) + (generate (:rhs bundle))))) (defn generate-set "Actually not sure what the mexpr representation of set looks like" - [tree context] + [tree] (throw (ex-info "Not Yet Implemented" {:feature "generate-set"}))) (defn generate-assign "Generate an assignment statement based on this `tree`. If the thing being assigned to is a function signature, then we have to do something different to if it's an atom." - [tree context] + [tree] (case (first (second tree)) - :fncall (generate-defn tree context) - :mexpr (map #(generate % context) (rest (second tree))) - (:mvar :atom) (generate-set tree context))) + :fncall (generate-defn tree) + (:mvar :atom) (generate-set tree))) (defn strip-leading-zeros "`read-string` interprets strings with leading zeros as octal; strip @@ -200,77 +187,69 @@ (defn generate "Generate lisp structure from this parse tree `p`. It is assumed that `p` has been simplified." - ([p] - (generate p :expr)) - ([p context] - (try - (expand-macros - (if - (coll? p) - (case (first p) - :λ "LAMBDA" - :λexpr (make-cons-cell - (generate (nth p 1) context) - (make-cons-cell (generate (nth p 2) context) - (generate (nth p 3) context))) - :args (make-beowulf-list (map #(generate % context) (rest p))) - :atom (symbol (second p)) - :bindings (generate (second p) context) - :body (make-beowulf-list (map #(generate % context) (rest p))) - (:coefficient :exponent) (generate (second p) context) - :cond (gen-cond p (if (= context :mexpr) :cond-mexpr context)) - :cond-clause (gen-cond-clause p context) - :decimal (read-string (apply str (map second (rest p)))) - :defn (generate-defn p context) - :dotted-pair (make-cons-cell - (generate (nth p 1) context) - (generate (nth p 2) context)) - :fncall (gen-fn-call p context) - :iexpr (gen-iexpr p context) - :integer (read-string (strip-leading-zeros (second p))) - :iop (case (second p) - "/" 'DIFFERENCE - "=" 'EQUAL - ">" 'GREATERP - "<" 'LESSP - "+" 'PLUS - "*" 'TIMES + [p] + (try + (expand-macros + (if + (coll? p) + (case (first p) + :λ "LAMBDA" + :λexpr (make-cons-cell + (generate (nth p 1)) + (make-cons-cell (generate (nth p 2)) + (generate (nth p 3)))) + :args (make-beowulf-list (map generate (rest p))) + :atom (symbol (second p)) + :bindings (generate (second p)) + :body (make-beowulf-list (map generate (rest p))) + (:coefficient :exponent) (generate (second p)) + :cond (gen-cond p) + :cond-clause (gen-cond-clause p) + :decimal (read-string (apply str (map second (rest p)))) + :defn (generate-assign p) + :dotted-pair (make-cons-cell + (generate (nth p 1)) + (generate (nth p 2))) + :fncall (gen-fn-call p) + :iexpr (gen-iexpr p) + :integer (read-string (strip-leading-zeros (second p))) + :iop (case (second p) + "/" 'DIFFERENCE + "=" 'EQUAL + ">" 'GREATERP + "<" 'LESSP + "+" 'PLUS + "*" 'TIMES ;; else - (throw (ex-info "Unrecognised infix operator symbol" - {:phase :generate - :fragment p}))) - :list (gen-dot-terminated-list (rest p)) - (:lhs :rhs) (generate (second p) context) - :mexpr (generate (second p) (if (= context :cond-mexpr) context :mexpr)) - :mconst (if (= context :cond-mexpr) - (case (second p) - ("T" "F" "NIL") (symbol (second p)) - ;; else - (list 'QUOTE (symbol (second p)))) - ;; else - (list 'QUOTE (symbol (second p)))) - :mvar (symbol (upper-case (second p))) - :number (generate (second p) context) - :octal (let [n (read-string (strip-leading-zeros (second p) "0")) - scale (generate (nth p 3) context)] - (* n (expt 8 scale))) + (throw (ex-info "Unrecognised infix operator symbol" + {:phase :generate + :fragment p}))) + :list (gen-dot-terminated-list (rest p)) + (:lhs :rhs) (generate (second p)) + :mexpr (generate (second p)) + :mconst (make-beowulf-list + (list 'QUOTE (symbol (upper-case (second p))))) + :mvar (symbol (upper-case (second p))) + :number (generate (second p)) + :octal (let [n (read-string (strip-leading-zeros (second p) "0")) + scale (generate (nth p 3))] + (* n (expt 8 scale))) ;; the quote read macro (which probably didn't exist in Lisp 1.5, but...) - :quoted-expr (make-beowulf-list (list 'QUOTE (generate (second p) context))) - :scale-factor (if - (empty? (second p)) 0 - (read-string (strip-leading-zeros (second p)))) - :scientific (let [n (generate (second p) context) - exponent (generate (nth p 3) context)] - (* n (expt 10 exponent))) - :sexpr (generate (second p) :sexpr) - :subr (symbol (second p)) + :quoted-expr (make-beowulf-list (list 'QUOTE (generate (second p)))) + :scale-factor (if + (empty? (second p)) 0 + (read-string (strip-leading-zeros (second p)))) + :scientific (let [n (generate (second p)) + exponent (generate (nth p 3))] + (* n (expt 10 exponent))) + :subr (symbol (second p)) ;; default - (throw (ex-info (str "Unrecognised head: " (first p)) - {:generating p}))) - p)) - (catch Throwable any - (throw (ex-info "Could not generate" - {:generating p} - any)))))) + (throw (ex-info (str "Unrecognised head: " (first p)) + {:generating p}))) + p)) + (catch Throwable any + (throw (ex-info "Could not generate" + {:generating p} + any))))) diff --git a/src/beowulf/reader/parser.clj b/src/beowulf/reader/parser.clj index 0fd7abe..2c062c8 100644 --- a/src/beowulf/reader/parser.clj +++ b/src/beowulf/reader/parser.clj @@ -51,21 +51,21 @@ "exprs := expr | exprs;" "mexpr := λexpr | fncall | defn | cond | mvar | mconst | iexpr | number | mexpr comment; - λexpr := λ lsqb bindings semi-colon opt-space body opt-space rsqb; - λ := 'λ' | 'lambda'; + λexpr := λ lsqb bindings semi-colon body rsqb; + λ := 'λ'; bindings := lsqb args rsqb | lsqb rsqb; - body := (opt-space mexpr semi-colon)* opt-space mexpr; + body := (mexpr semi-colon opt-space)* mexpr; fncall := fn-name bindings; lsqb := '['; rsqb := ']'; - lbrace := '{'; - rbrace := '}'; + lbrace := '{'; + rbrace := '}'; defn := mexpr opt-space '=' opt-space mexpr; cond := lsqb (opt-space cond-clause semi-colon opt-space)* cond-clause rsqb; cond-clause := mexpr opt-space arrow opt-space mexpr opt-space; arrow := '->'; args := arg | (opt-space arg semi-colon opt-space)* opt-space arg opt-space; - arg := mexpr; + arg := mexpr | sexpr; fn-name := mvar; mvar := #'[a-z][a-z0-9]*'; mconst := #'[A-Z][A-Z0-9]*'; diff --git a/src/beowulf/reader/simplify.clj b/src/beowulf/reader/simplify.clj index a8057a0..fdfa3c7 100644 --- a/src/beowulf/reader/simplify.clj +++ b/src/beowulf/reader/simplify.clj @@ -110,7 +110,7 @@ (throw (ex-info "Cannot parse meta expressions in strict mode" {:cause :strict})) - [:mexpr (simplify-tree (second p) :mexpr)]) + (simplify-tree (second p) :mexpr)) :list (if (= context :mexpr) [:fncall @@ -118,7 +118,7 @@ [:args (apply vector (map simplify-tree (rest p)))]] (map #(simplify-tree % context) p)) :raw (first (remove empty? (map simplify-tree (rest p)))) - :sexpr [:sexpr (simplify-tree (second p) :sexpr)] + :sexpr (simplify-tree (second p) :sexpr) ;;default p))) :else p))) diff --git a/test/beowulf/bootstrap_test.clj b/test/beowulf/bootstrap_test.clj index f3233af..242d186 100644 --- a/test/beowulf/bootstrap_test.clj +++ b/test/beowulf/bootstrap_test.clj @@ -1,27 +1,20 @@ (ns beowulf.bootstrap-test - (:require [beowulf.bootstrap :refer [EVAL]] - [beowulf.cons-cell :refer [F make-cons-cell T]] - [beowulf.host :refer [ASSOC ATOM ATOM? CAAAAR CADDDR CADDR CADR - CAR CDR EQ EQUAL PAIRLIS]] + (:require [clojure.test :refer [deftest testing is]] + [beowulf.cons-cell :refer [make-cons-cell T F]] + [beowulf.host :refer [ASSOC ATOM ATOM? CAR CAAAAR CADR + CADDR CADDDR CDR EQ EQUAL + PAIRLIS]] [beowulf.oblist :refer [NIL]] - [beowulf.read :refer [gsp READ]] - [clojure.test :refer [deftest is testing]])) + [beowulf.read :refer [gsp]])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; -;;; This file is primarily tests of the functions in `beowulf.bootstrap` - which +;;; This file is primarily tests of the functions in `beowulf.eval` - which ;;; are Clojure functions, but aim to provide sufficient functionality that ;;; Beowulf can get up to the level of running its own code. ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defn- reps - "'Read eval print string', or 'read eval print single'. - Reads and evaluates one input string, and returns the - output string." - [input] - (with-out-str (print (EVAL (READ input))))) - (deftest atom-tests (testing "ATOM" (let [expected T @@ -70,12 +63,12 @@ (is (= actual expected) "A is CAR of (A B C D)")) (is (thrown-with-msg? Exception - #"Ne can tace CAR of `.*" + #"Cannot take CAR of `.*" (CAR 'T)) "Can't take the CAR of an atom") (is (thrown-with-msg? Exception - #"Ne can tace CAR of `.*" + #"Cannot take CAR of `.*" (CAR 7)) "Can't take the CAR of a number")) (testing "CDR" @@ -89,12 +82,12 @@ (is (= (CAR actual) expected) "the CAR of that cons-cell is B")) (is (thrown-with-msg? Exception - #"Ne can tace CDR of `.*" + #"Cannot take CDR of `.*" (CDR 'T)) "Can't take the CDR of an atom") (is (thrown-with-msg? Exception - #"Ne can tace CDR of `.*" + #"Cannot take CDR of `.*" (CDR 7)) "Can't take the CDR of a number")) (let [s (gsp "((((1 . 2) 3)(4 5) 6)(7 (8 9) (10 11 12) 13) 14 (15 16) 17)")] @@ -203,3 +196,13 @@ 'D (gsp "((A . (M N)) (B . (CAR X)) (C . (QUOTE M)) (C . (CDR X)))")))] (is (= actual expected))))) + +;; TODO: need to reimplement this in lisp_test +;; (deftest sublis-tests +;; (testing "sublis" +;; (let [expected "(SHAKESPEARE WROTE (THE TEMPEST))" +;; actual (print-str +;; (SUBLIS +;; (gsp "((X . SHAKESPEARE) (Y . (THE TEMPEST)))") +;; (gsp "(X WROTE Y)")))] +;; (is (= actual expected))))) diff --git a/test/beowulf/host_test.clj b/test/beowulf/host_test.clj index 7e5e1ff..8ed4b11 100644 --- a/test/beowulf/host_test.clj +++ b/test/beowulf/host_test.clj @@ -15,12 +15,12 @@ (is (= actual expected))) (is (thrown-with-msg? Exception - #"Un-ġefōg þing in RPLACA.*" + #"Invalid value in RPLACA.*" (RPLACA (make-beowulf-list '(A B C D E)) "F")) "You can't represent a string in Lisp 1.5") (is (thrown-with-msg? Exception - #"Uncynlic miercels in RPLACA.*" + #"Invalid cell in RPLACA.*" (RPLACA '(A B C D E) 'F)) "You can't RPLACA into anything which isn't a MutableSequence.") ) diff --git a/test/beowulf/lisp_test.clj b/test/beowulf/lisp_test.clj index 7d9fa64..933bddd 100644 --- a/test/beowulf/lisp_test.clj +++ b/test/beowulf/lisp_test.clj @@ -24,22 +24,22 @@ :file "resources/lisp1.5.lsp"} any)))))) -(deftest APPEND-tests - (testing "append - dot-terminated lists" - (let [expected "(A B C . D)" - actual (reps "(APPEND '(A B) (CONS 'C 'D))")] - (is (= actual expected))) - (let [expected "(A B C . D)" - actual (reps "(APPEND (CONS 'A (CONS 'B NIL)) (CONS 'C 'D))")] - (is (= actual expected))) + (deftest APPEND-tests + (testing "append - dot-terminated lists" + (let [expected "(A B C . D)" + actual (reps "(APPEND '(A B) (CONS 'C 'D))")] + (is (= actual expected))) + (let [expected "(A B C . D)" + actual (reps "(APPEND (CONS 'A (CONS 'B NIL)) (CONS 'C 'D))")] + (is (= actual expected))) ;; this is failing: https://github.com/simon-brooke/beowulf/issues/5 - (let [expected "(A B C . D)" - actual (reps "(APPEND '(A B) '(C . D))")] - (is (= actual expected)))) - (testing "append - straight lists" - (let [expected "(A B C D E)" - actual (reps "(APPEND '(A B) '(C D E))")] - (is (= actual expected))))) + (let [expected "(A B C . D)" + actual (reps "(APPEND '(A B) '(C . D))")] + (is (= actual expected)))) + (testing "append - straight lists" + (let [expected "(A B C D E)" + actual (reps "(APPEND '(A B) '(C D E))")] + (is (= actual expected))))) (deftest COPY-tests (testing "copy NIL" @@ -74,10 +74,10 @@ (is (= actual expected)))) (testing "divide by zero" (let [input "(DIVIDE 22 0)"] - (is (thrown-with-msg? clojure.lang.ExceptionInfo - #"Uncynlic þegnung: Divide by zero" + (is (thrown-with-msg? ArithmeticException + #"Divide by zero" (reps input))))) - + ;; TODO: need to write tests for GET but I don't really ;; understand what the correct behaviour is. @@ -107,7 +107,7 @@ input "(INTERSECTION '(A B C D) '(F D E C))" actual (reps input)] (is (= actual expected))))) - + (deftest LENGTH-tests (testing "length of NIL" (let [expected "0" @@ -129,8 +129,8 @@ input "(LENGTH (PAIR '(A B C) '(1 2 3)))" actual (reps input)] (is (= actual expected)))))) - - + + (deftest MEMBER-tests (testing "member" (let [expected "T" @@ -146,23 +146,5 @@ actual (reps "(MEMBER 'BERTRAM '(ALBERT BELINDA CHARLIE DORIS ELFREDA FRED))")] (is (= actual expected))))) -;; This is failing, and although yes, it does matter, I have not yet tracked the reason. -;; (deftest sublis-tests -;; (testing "sublis" -;; (let [expected "(SHAKESPEARE WROTE (THE TEMPEST))" -;; actual (reps -;; "(SUBLIS -;; '((X . SHAKESPEARE) (Y . (THE TEMPEST))) -;; '(X WROTE Y))")] -;; (is (= actual expected))))) - -(deftest prog-tests - (testing "PROG" - (let [expected "5" - actual (reps "(PROG (X) - (SETQ X 1) - START - (SETQ X (ADD1 X)) - (COND ((EQ X 5) (RETURN X)) - (T (GO START))))")] - (is (= actual expected))))) \ No newline at end of file + + \ No newline at end of file diff --git a/test/beowulf/mexpr_test.clj b/test/beowulf/mexpr_test.clj index 2f74389..719d9e1 100644 --- a/test/beowulf/mexpr_test.clj +++ b/test/beowulf/mexpr_test.clj @@ -68,10 +68,10 @@ (deftest conditional-tests (testing "Conditional expressions" - (let [expected "(COND ((ATOM X) X) (T (FF (CAR X))))" + (let [expected "(COND ((ATOM X) X) ((QUOTE T) (FF (CAR X))))" actual (print-str (gsp "[atom[x]->x; T->ff[car[x]]]"))] (is (= actual expected))) - (let [expected "(LABEL FF (LAMBDA (X) (COND ((ATOM X) X) (T (FF (CAR X))))))" + (let [expected "(LABEL FF (LAMBDA (X) (COND ((ATOM X) X) ((QUOTE T) (FF (CAR X))))))" actual (print-str (generate (simplify-tree @@ -88,6 +88,6 @@ (deftest assignment-tests (testing "Function assignment" - (let [expected "(PUT (QUOTE FF) (QUOTE EXPR) (QUOTE (LAMBDA (X) (COND ((ATOM X) X) (T (FF (CAR X)))))))" + (let [expected "(SET (QUOTE FF) (QUOTE (LAMBDA (X) (COND ((ATOM X) X) ((QUOTE T) (FF (CAR X)))))))" actual (print-str (gsp "ff[x]=[atom[x] -> x; T -> ff[car[x]]]"))] (is (= actual expected)))))