diff --git a/docs/cloverage/beowulf/host.clj.html b/docs/cloverage/beowulf/host.clj.html index 6437d2b..e11a000 100644 --- a/docs/cloverage/beowulf/host.clj.html +++ b/docs/cloverage/beowulf/host.clj.html @@ -130,19 +130,19 @@ 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})))
@@ -283,19 +283,19 @@ 093      (empty? path) l
- + 094      (not (instance? ConsCell l)) (throw (ex-info (str "Ne liste: "
- + 095                                                        l "; " (type l))
- + 096                                                   {:phase :eval
097                                                    :function "universal access function"
- + 098                                                    :args [l path]
@@ -310,19 +310,19 @@ 102              \d (uaf (.getCdr l) (butlast path))
- + 103              (throw (ex-info (str "uaf: unexpected letter in path (only `a` and `d` permitted): "
- + 104                                   (last path))
- + 105                              {:phase :eval
106                               :function "universal access function"
- + 107                               :args [l path]
@@ -568,7 +568,7 @@ 188      (if
- + 189       (or
@@ -580,7 +580,7 @@ 192        (symbol? value)
- + 193        (= value NIL))
@@ -619,13 +619,13 @@ 205                    any))))
- + 206        (throw (ex-info
- + 207                (str "Un-ġefōg þing in RPLACD: `" value "` (" (type value) ")")
- + 208                {:cause :bad-value
@@ -634,19 +634,19 @@ 210                 :function :rplacd
- + 211                 :args (list cell value)
212                 :type :beowulf})))
- + 213      (throw (ex-info
- + 214              (str "Uncynlic miercels in RPLACD: `" cell "` (" (type cell) ")")
- + 215              {:cause :bad-cell
@@ -655,7 +655,7 @@ 217               :detail :rplacd
- + 218               :args (list cell value)
@@ -682,7 +682,7 @@ 226  
- + 227  (defmacro NULL
@@ -691,13 +691,13 @@ 229    [x]
- + 230    `(if (= ~x NIL) T F))
231  
- + 232  (defmacro NILP
@@ -706,7 +706,7 @@ 234    [x]
- + 235    `(if (= ~x NIL) T NIL))
@@ -847,13 +847,13 @@ 281    ;; (println "  filtered: " (seq (filter #{F NIL} args)))
- + 282    (cond (= NIL args) T
283          (seq? args) (if (seq (filter #{F NIL} args)) F T)
- + 284          :else T))
@@ -889,13 +889,13 @@ 295    ;; (println "  filtered: " (seq (remove #{F NIL} args)))
- + 296    (cond (= NIL args) F
- + 297          (seq? args) (if (seq (remove #{F NIL} args)) T F)
- + 298          :else F))
@@ -1078,7 +1078,7 @@ 358    (let [p (apply * args)]
- + 359      (if (integer? p) p (float p))))
@@ -1093,7 +1093,7 @@ 363    (let [d (- x y)]
- + 364      (if (integer? d) d (float d))))
@@ -1153,7 +1153,7 @@ 383    [x]
- + 384    (dec x))
@@ -1165,7 +1165,7 @@ 387    [x]
- + 388    (if (integer? x) T F))
@@ -1189,7 +1189,7 @@ 395    [x y]
- + 396    (if (< x y) T F))
@@ -1201,7 +1201,7 @@ 399    [x y]
- + 400    (if (> x y) T F))
@@ -1237,7 +1237,7 @@ 411    [& args]
- + 412    (throw (ex-info "LISP STÆFLEAHTER" {:args args
@@ -1249,7 +1249,7 @@ 415                                        :type :lisp
- + 416                                        :code (or (first args) 'A1)})))
@@ -1334,7 +1334,7 @@ 443    [target plist]
- 444    (if (and (instance? ConsCell plist)(even? (count plist))) + 444    (if (and (instance? ConsCell plist) (even? (count plist)))
445      (cond (= plist NIL) NIL @@ -1558,215 +1558,218 @@ 518    [a-list indicator]
- - 519    (map + + 519    (doall
- - 520     #(PUT (CAR %) indicator (CDR %)) + + 520     (map +
+ + 521      #(when (PUT (CAR %) indicator (CDR %)) (CAR %))
- 521     a-list)) + 522      a-list)))
- 522   + 523  
- 523  (defn DEFINE + 524  (defn DEFINE
- 524    "Bootstrap-only version of `DEFINE` which, post boostrap, can be overwritten  + 525    "Bootstrap-only version of `DEFINE` which, post boostrap, can be overwritten 
- 525    in LISP.  + 526    in LISP. 
- 526   + 527  
- 527    The single argument to `DEFINE` should be an association list of symbols to + 528    The single argument to `DEFINE` should be an association list of symbols to
- 528     lambda functions. See page 58 of the manual." + 529     lambda functions. See page 58 of the manual."
- 529    [a-list] + 530    [a-list]
- 530    (DEFLIST a-list 'EXPR)) + 531    (DEFLIST a-list 'EXPR))
- 531   + 532  
- 532  (defn SET + 533  (defn SET
- 533    "Implementation of SET in Clojure. Add to the `oblist` a binding of the + 534    "Implementation of SET in Clojure. Add to the `oblist` a binding of the
- 534     value of `var` to the value of `val`. NOTE WELL: this is not SETQ!" + 535     value of `var` to the value of `val`. NOTE WELL: this is not SETQ!"
- 535    [symbol val] + 536    [symbol val]
- 536    (PUT symbol 'APVAL val)) + 537    (PUT symbol 'APVAL val))
- 537   + 538  
- 538  ;;;; TRACE and friends ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + 539  ;;;; TRACE and friends ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- 539   + 540  
- 540  (def traced-symbols + 541  (def traced-symbols
- 541    "Symbols currently being traced." + 542    "Symbols currently being traced."
- 542    (atom #{})) + 543    (atom #{}))
- 543   + 544  
- 544  (defn traced? + 545  (defn traced?
- 545    "Return `true` iff `s` is a symbol currently being traced, else `nil`." + 546    "Return `true` iff `s` is a symbol currently being traced, else `nil`."
- 546    [s] + 547    [s]
- 547    (try (contains? @traced-symbols s) + 548    (try (contains? @traced-symbols s)
- 548         (catch Throwable _ nil))) + 549         (catch Throwable _ nil)))
- 549   + 550  
- 550  (defn TRACE + 551  (defn TRACE
- 551    "Add this `s` to the set of symbols currently being traced. If `s` + 552    "Add this `s` to the set of symbols currently being traced. If `s`
- 552     is not a symbol or sequence of symbols, does nothing." + 553     is not a symbol or sequence of symbols, does nothing."
- 553    [s] + 554    [s]
- 554    (swap! traced-symbols + 555    (swap! traced-symbols
- 555           #(cond + 556           #(cond
- 556              (symbol? s) (conj % s) + 557              (symbol? s) (conj % s)
- 557              (and (seq? s) (every? symbol? s)) (union % (set s)) + 558              (and (seq? s) (every? symbol? s)) (union % (set s))
- 558              :else %))) + 559              :else %)))
- 559   + 560  
- 560  (defn UNTRACE + 561  (defn UNTRACE
- 561    "Remove this `s` from the set of symbols currently being traced. If `s` + 562    "Remove this `s` from the set of symbols currently being traced. If `s`
- 562     is not a symbol or sequence of symbols, does nothing." + 563     is not a symbol or sequence of symbols, does nothing."
- 563    [s] + 564    [s]
- 564    (cond + 565    (cond
- 565      (symbol? s) (swap! traced-symbols #(set (remove (fn [x] (= s x)) %))) + 566      (symbol? s) (swap! traced-symbols #(set (remove (fn [x] (= s x)) %)))
- 566      (and (seq? s) (every? symbol? s)) (map UNTRACE s)) + 567      (and (seq? s) (every? symbol? s)) (map UNTRACE s))
- 567    @traced-symbols) + 568    @traced-symbols)
- 568   + 569  
- 569  ;;;; Extensions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + 570  ;;;; Extensions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- 570   + 571  
- 571  (defn DOC + 572  (defn DOC
- 572    "Open the page for this `symbol` in the Lisp 1.5 manual, if known, in the  + 573    "Open the page for this `symbol` in the Lisp 1.5 manual, if known, in the 
- 573      default web browser. + 574      default web browser.
- 574      + 575     
- 575     **NOTE THAT** this is an extension function, not available in strct mode." + 576     **NOTE THAT** this is an extension function, not available in strct mode."
- 576    [symbol] + 577    [symbol]
- 577    (when (lax? 'DOC) + 578    (when (lax? 'DOC)
- 578      (open-doc symbol))) + 579      (open-doc symbol)))
- 579   + 580  
- 580  (defn CONSP + 581  (defn CONSP
- 581    "Return `T` if object `o` is a cons cell, else `F`. + 582    "Return `T` if object `o` is a cons cell, else `F`.
- 582      + 583     
- 583     **NOTE THAT** this is an extension function, not available in strct mode.  + 584     **NOTE THAT** this is an extension function, not available in strct mode. 
- 584     I believe that Lisp 1.5 did not have any mechanism for testing whether an + 585     I believe that Lisp 1.5 did not have any mechanism for testing whether an
- 585     argument was, or was not, a cons cell." + 586     argument was, or was not, a cons cell."
- 586    [o] + 587    [o]
- 587    (when (lax? 'CONSP) + 588    (when (lax? 'CONSP)
- 588      (if (instance? ConsCell o) 'T 'F))) + 589      (if (instance? ConsCell o) 'T 'F)))
diff --git a/docs/cloverage/index.html b/docs/cloverage/index.html index 69296cf..dbe60af 100644 --- a/docs/cloverage/index.html +++ b/docs/cloverage/index.html @@ -67,20 +67,20 @@ beowulf.host
1144
1310
-46.62 % + style="width:56.44047135310849%; + float:left;"> 1389
1072
+56.44 %
163
37
63
-76.05 % -58867263 + style="width:75.37878787878788%; + float:left;"> 199
32
33
+87.50 % +58967264 beowulf.interop
Totals: -65.64 % +68.60 % -75.70 % +77.76 % diff --git a/docs/codox/beowulf.bootstrap.html b/docs/codox/beowulf.bootstrap.html index 72c621f..eaa1806 100644 --- a/docs/codox/beowulf.bootstrap.html +++ b/docs/codox/beowulf.bootstrap.html @@ -1,17 +1,24 @@ 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.

+

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.

+

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.

+

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 +

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 diff --git a/docs/codox/beowulf.cons-cell.html b/docs/codox/beowulf.cons-cell.html index cc83668..39996a5 100644 --- a/docs/codox/beowulf.cons-cell.html +++ b/docs/codox/beowulf.cons-cell.html @@ -1,3 +1,16 @@ -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 1d60abf..f796bb3 100644 --- a/docs/codox/beowulf.core.html +++ b/docs/codox/beowulf.core.html @@ -1,3 +1,8 @@ -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

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 diff --git a/docs/codox/beowulf.gendoc.html b/docs/codox/beowulf.gendoc.html index fa4087e..c40564c 100644 --- a/docs/codox/beowulf.gendoc.html +++ b/docs/codox/beowulf.gendoc.html @@ -1,4 +1,13 @@ 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 +

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 efef2cb..0a9aadc 100644 --- a/docs/codox/beowulf.host.html +++ b/docs/codox/beowulf.host.html @@ -1,19 +1,94 @@ -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:

+

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.

+

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

+

hit-or-miss-assoc

(hit-or-miss-assoc target plist)

Find the position of the binding of this target in a Lisp 1.5 property list plist.

+

Lisp 1.5 property lists are not assoc lists, but lists of the form (name value name value name value...). It’s therefore necessary to recurse down the list two entries at a time to avoid confusing names with values.

+

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.

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

+

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 diff --git a/docs/codox/beowulf.interop.html b/docs/codox/beowulf.interop.html index 59e1c5b..f1fcf7e 100644 --- a/docs/codox/beowulf.interop.html +++ b/docs/codox/beowulf.interop.html @@ -1,11 +1,17 @@ -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

+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. +
  5. a symbol bound in the host environment to a function; or
  6. +
  7. 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.

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 +

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 648f733..c87c07b 100644 --- a/docs/codox/beowulf.io.html +++ b/docs/codox/beowulf.io.html @@ -2,12 +2,18 @@ ""> 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.

+

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

+

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.

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 3a82449..3631591 100644 --- a/docs/codox/beowulf.manual.html +++ b/docs/codox/beowulf.manual.html @@ -1,3 +1,8 @@ -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 ea54aa2..155a64b 100644 --- a/docs/codox/beowulf.oblist.html +++ b/docs/codox/beowulf.oblist.html @@ -1,5 +1,9 @@ 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 +

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 1a7c002..bd83a97 100644 --- a/docs/codox/beowulf.read.html +++ b/docs/codox/beowulf.read.html @@ -3,7 +3,14 @@ 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. -
  3. 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.
  4. +
  5. 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;
  6. +
  7. 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.
-

Both these extensions can be disabled by using the --strict command line switch.

gsp

(gsp s)

Shortcut macro - the internals of read; or, if you like, read-string. Argument s should be a string representation of a valid Lisp expression.

number-lines

(number-lines s)(number-lines s e)

TODO: write docs

READ

(READ)(READ input)

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.

read-from-console

(read-from-console)

Attempt to read a complete lisp expression from the console. NOTE that this will only really work for S-Expressions, not M-Expressions.

strip-line-comments

(strip-line-comments s)

Strip blank lines and comment lines from this string s, expected to be Lisp source.

\ No newline at end of file +

Both these extensions can be disabled by using the --strict command line switch.

+

gsp

(gsp s)

Shortcut macro - the internals of read; or, if you like, read-string. Argument s should be a string representation of a valid Lisp expression.

+

number-lines

(number-lines s)(number-lines s e)

TODO: write docs

+

READ

(READ)(READ input)

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.

+

read-from-console

(read-from-console prompt)

Attempt to read a complete lisp expression from the console.

+

There’s a major problem here that the read-chars reader messes up testing. We need to be able to disable it while testing!

+

strip-line-comments

(strip-line-comments s)

Strip blank lines and comment lines from this string s, expected to be Lisp source.

+
\ No newline at end of file diff --git a/docs/codox/beowulf.reader.char-reader.html b/docs/codox/beowulf.reader.char-reader.html index e726009..9ef00d6 100644 --- a/docs/codox/beowulf.reader.char-reader.html +++ b/docs/codox/beowulf.reader.char-reader.html @@ -2,15 +2,19 @@ ""> 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)

+

What’s needed (rough specification)

    -
  1. Carriage return does not cause input to be returned, unless a. the number of open brackets ( and closing brackets ) match; and b. the number of open square brackets [ and closing square brackets ] also match;
  2. -
  3. aborts editing and returns the string STOP;
  4. -
  5. 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);
  6. -
  7. offers potential auto-completions taken from the value of (OBLIST), ideally the current value, not the value at the time the session started;
  8. -
  9. and offer movement and editing within the line.
  10. +
  11. Carriage return does not cause input to be returned, unless a. the number of open brackets ( and closing brackets ) match; and b. the number of open square brackets [ and closing square brackets ] also match;
  12. +
  13. aborts editing and returns the string STOP;
  14. +
  15. 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);
  16. +
  17. offers potential auto-completions taken from the value of (OBLIST), ideally the current value, not the value at the time the session started;
  18. +
  19. 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

build-completer

(build-completer)

Build a completer which takes tokens from the oblist.

-

This is sort-of working, in as much as hitting on a blank line will show a table of values from the oblist, but hitting after you’ve started input does not show potential completions for tokens you’ve started.

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 fully work yet, but it is in the API because I hope that it will work later!

\ No newline at end of file +

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

+

build-completer

(build-completer)

Build a completer which takes tokens from the oblist.

+

This is sort-of working, in as much as hitting on a blank line will show a table of values from the oblist, but hitting after you’ve started input does not show potential completions for tokens you’ve started.

+

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

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

+

NOTE THAT this does not fully 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 f2d763e..417a91e 100644 --- a/docs/codox/beowulf.reader.generate.html +++ b/docs/codox/beowulf.reader.generate.html @@ -1,13 +1,13 @@ -beowulf.reader.generate documentation

beowulf.reader.generate

Generating S-Expressions from parse trees.

-

From Lisp 1.5 Programmers Manual, page 10

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

We are now in a position to define the universal LISP function evalquote[fn;args], When evalquote is given a function and a list of arguments for that function, it computes the value of the function applied to the arguments. LISP functions have S-expressions as arguments. In particular, the argument fn of the function evalquote must be an S-expression. Since we have been writing functions as M-expressions, it is necessary to translate them into S-expressions.

-

The following rules define a method of translating functions written in the meta-language into S-expressions. 1. If the function is represented by its name, it is translated by changing all of the letters to upper case, making it an atomic symbol. Thus car is translated to CAR. 2. If the function uses the lambda notation, then the expression λ[[x ..;xn]; ε] is translated into (LAMBDA (X1 ...XN) ε*), where ε* is the translation of ε. 3. If the function begins with label, then the translation of label[α;ε] is (LABEL α* ε*).

-

Forms are translated as follows: 1. A variable, like a function name, is translated by using uppercase letters. Thus the translation of var1 is VAR1. 2. The obvious translation of letting a constant translate into itself will not work. Since the translation of x is X, the translation of X must be something else to avoid ambiguity. The solution is to quote it. Thus X is translated into (QUOTE X). 3. The form fn[argl;. ..;argn] is translated into (fn* argl* ...argn*) 4. The conditional expression [pl-el;...;pn-en] is translated into (COND (p1* e1*)...(pn* en*))

-

Examples

+

The following rules define a method of translating functions written in the meta-language into S-expressions. 1. If the function is represented by its name, it is translated by changing all of the letters to upper case, making it an atomic symbol. Thus car is translated to CAR. 2. If the function uses the lambda notation, then the expression λ[[x ..;xn]; ε] is translated into (LAMBDA (X1 ...XN) ε*), where ε* is the translation of ε. 3. If the function begins with label, then the translation of label[α;ε] is (LABEL α* ε*).

+

Forms are translated as follows: 1. A variable, like a function name, is translated by using uppercase letters. Thus the translation of var1 is VAR1. 2. The obvious translation of letting a constant translate into itself will not work. Since the translation of x is X, the translation of X must be something else to avoid ambiguity. The solution is to quote it. Thus X is translated into (QUOTE X). 3. The form fn[argl;. ..;argn] is translated into (fn* argl* ...argn*) 4. The conditional expression [pl-el;...;pn-en] is translated into (COND (p1* e1*)...(pn* en*))

+

Examples

  M-expressions                                  S-expressions             
 
   x                                              X                         
@@ -21,4 +21,15 @@
        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 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 diff --git a/docs/codox/beowulf.reader.macros.html b/docs/codox/beowulf.reader.macros.html index 55003ec..5c9d10c 100644 --- a/docs/codox/beowulf.reader.macros.html +++ b/docs/codox/beowulf.reader.macros.html @@ -2,4 +2,7 @@ ""> 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 +

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 25eb874..c4a43f0 100644 --- a/docs/codox/beowulf.reader.parser.html +++ b/docs/codox/beowulf.reader.parser.html @@ -1,3 +1,5 @@ -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 013d66f..2b3f8ba 100644 --- a/docs/codox/beowulf.reader.simplify.html +++ b/docs/codox/beowulf.reader.simplify.html @@ -1,4 +1,9 @@ -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 +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/beowulf.scratch.html b/docs/codox/beowulf.scratch.html index 671f5a6..3209599 100644 --- a/docs/codox/beowulf.scratch.html +++ b/docs/codox/beowulf.scratch.html @@ -1,4 +1,8 @@ -beowulf.scratch documentation

beowulf.scratch

This namespace is for temporary functions and is intentionally excluded from Git.

fns

TODO: write docs

interop-listify-q-name

(interop-listify-q-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.

mogrify-plist

(mogrify-plist entry fns)

TODO: write docs

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

beowulf.scratch

This namespace is for temporary functions and is intentionally excluded from Git.

+

fns

TODO: write docs

+

interop-listify-q-name

(interop-listify-q-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.

+

mogrify-plist

(mogrify-plist entry fns)

TODO: write docs

+
\ No newline at end of file diff --git a/docs/codox/further_reading.html b/docs/codox/further_reading.html index 2c027dd..d2d3a62 100644 --- a/docs/codox/further_reading.html +++ b/docs/codox/further_reading.html @@ -1,17 +1,19 @@ -Further Reading

Further Reading

+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 +
  • 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.
  • +
  • MIT AI Memo 1, John McCarthy, September 1958 This is, as far as I can find, the earliest specification document of the Lisp project.
  • +
  • Lisp 1 Programmer’s Manual, Phyllis Fox, March 1960
  • +
  • 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.
  • +
  • Early LISP History (1956 - 1959), Herbert Stoyan, August 1984
  • +
  • +

    The Roots of Lisp, Paul Graham, 2001

    +
  • +
  • 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.

    +
    +
  • + +
    \ No newline at end of file diff --git a/docs/codox/index.html b/docs/codox/index.html index 01c5b4f..f1b6eac 100644 --- a/docs/codox/index.html +++ b/docs/codox/index.html @@ -1,3 +1,19 @@ -Beowulf 0.3.1-SNAPSHOT

    Beowulf 0.3.1-SNAPSHOT

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

    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.

    beowulf.scratch

    This namespace is for temporary functions and is intentionally excluded from Git.

    Public variables and functions:

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

    Beowulf 0.3.1-SNAPSHOT

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

    +

    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.

    +

    beowulf.scratch

    This namespace is for temporary functions and is intentionally excluded from Git.

    +

    Public variables and functions:

    \ No newline at end of file diff --git a/docs/codox/intro.html b/docs/codox/intro.html index 03c2696..5aea87d 100644 --- a/docs/codox/intro.html +++ b/docs/codox/intro.html @@ -1,64 +1,64 @@ -beowulf

    beowulf

    -

    Þý liste cræfte spræc

    +beowulf

    beowulf

    +

    Þý liste cræfte spræc

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

    Beowulf logo

    -

    Contents

    +

    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?!!?!

    +

    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

    +

    Status

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

    -

    Project Target

    +

    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

    +

    Invoking

    Invoke with

    java -jar target/uberjar/beowulf-0.3.0-standalone.jar --help
     
    @@ -72,764 +72,171 @@ without extensions.

    To end a session, type STOP at the command prompt.

    -

    Building and Invoking

    +

    Building and Invoking

    Build with

    lein uberjar
     
    -

    Reader macros

    +

    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.

    -

    Functions and symbols implemented

    +

    Functions and symbols implemented

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Function Type Signature Implementation Documentation
    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 ? ?
    AND Host lambda function ? 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 ? ? 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 ? 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 ? 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 ? ? ?
    CAAADR Lisp lambda function ? ? ?
    CAAAR Lisp lambda function ? ? ?
    CAADAR Lisp lambda function ? ? ?
    CAADDR Lisp lambda function ? ? ?
    CAADR Lisp lambda function ? ? ?
    CAAR Lisp lambda function ? ? ?
    CADAAR Lisp lambda function ? ? ?
    CADADR Lisp lambda function ? ? ?
    CADAR Lisp lambda function ? ? ?
    CADDAR Lisp lambda function ? ? ?
    CADDDR Lisp lambda function ? ? ?
    CADDR Lisp lambda function ? ? ?
    CADR Lisp lambda function ? ? ?
    CDAAAR Lisp lambda function ? ? ?
    CDAADR Lisp lambda function ? ? ?
    CDAAR Lisp lambda function ? ? ?
    CDADAR Lisp lambda function ? ? ?
    CDADDR Lisp lambda function ? ? ?
    CDADR Lisp lambda function ? ? ?
    CDAR Lisp lambda function ? ? ?
    CDDAAR Lisp lambda function ? ? ?
    CDDADR Lisp lambda function ? ? ?
    CDDAR Lisp lambda function ? ? ?
    CDDDAR Lisp lambda function ? ? ?
    CDDDDR Lisp lambda function ? ? ?
    CDDDR Lisp lambda function ? ? ?
    CDDR Lisp lambda function ? ? ?
    CDR Host lambda function ? 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 ? 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
    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 ? ?
    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
    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. 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 Host lambda function ? ?
    PRETTY ? ? ?
    PRINT ? PSEUDO-FUNCTION see manual pages 65, 84
    PROG Host nlambda function ? The accursed PROG feature. See page 71 of the manual. Lisp 1.5 introduced PROG, and most Lisps have been stuck with it ever since. It introduces imperative programming into what should be a pure functional language, and consequently it’s going to be a pig to implement. Broadly, PROG is a variadic pseudo function called as a FEXPR (or possibly an FSUBR, although I’m not presently sure that would even work.) The arguments, which are unevaluated, are a list of forms, the first of which is expected to be a list of symbols which will be treated as names of variables within the program, and the rest of which (the ‘program body’) are either lists or symbols. Lists are treated as Lisp expressions which may be evaulated in turn. Symbols are treated as targets for the GO statement. GO: A GO statement takes the form of (GO target), where target should be one of the symbols which occur at top level among that particular invocation of 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
    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 strct 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
    Function Type Signature Implementation Documentation
    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 ? ?
    AND Host lambda function ? 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 ? ? 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 ? 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 ? 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 ? ? ?
    CAAADR Lisp lambda function ? ? ?
    CAAAR Lisp lambda function ? ? ?
    CAADAR Lisp lambda function ? ? ?
    CAADDR Lisp lambda function ? ? ?
    CAADR Lisp lambda function ? ? ?
    CAAR Lisp lambda function ? ? ?
    CADAAR Lisp lambda function ? ? ?
    CADADR Lisp lambda function ? ? ?
    CADAR Lisp lambda function ? ? ?
    CADDAR Lisp lambda function ? ? ?
    CADDDR Lisp lambda function ? ? ?
    CADDR Lisp lambda function ? ? ?
    CADR Lisp lambda function ? ? ?
    CDAAAR Lisp lambda function ? ? ?
    CDAADR Lisp lambda function ? ? ?
    CDAAR Lisp lambda function ? ? ?
    CDADAR Lisp lambda function ? ? ?
    CDADDR Lisp lambda function ? ? ?
    CDADR Lisp lambda function ? ? ?
    CDAR Lisp lambda function ? ? ?
    CDDAAR Lisp lambda function ? ? ?
    CDDADR Lisp lambda function ? ? ?
    CDDAR Lisp lambda function ? ? ?
    CDDDAR Lisp lambda function ? ? ?
    CDDDDR Lisp lambda function ? ? ?
    CDDDR Lisp lambda function ? ? ?
    CDDR Lisp lambda function ? ? ?
    CDR Host lambda function ? 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 ? 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
    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 ? ?
    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
    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. 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 Host lambda function ? ?
    PRETTY ? ? ?
    PRINT ? PSEUDO-FUNCTION see manual pages 65, 84
    PROG Host nlambda function ? The accursed PROG feature. See page 71 of the manual. Lisp 1.5 introduced PROG, and most Lisps have been stuck with it ever since. It introduces imperative programming into what should be a pure functional language, and consequently it’s going to be a pig to implement. Broadly, PROG is a variadic pseudo function called as a FEXPR (or possibly an FSUBR, although I’m not presently sure that would even work.) The arguments, which are unevaluated, are a list of forms, the first of which is expected to be a list of symbols which will be treated as names of variables within the program, and the rest of which (the ‘program body’) are either lists or symbols. Lists are treated as Lisp expressions which may be evaulated in turn. Symbols are treated as targets for the GO statement. GO: A GO statement takes the form of (GO target), where target should be one of the symbols which occur at top level among that particular invocation of 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
    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 strct 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

    Functions described as ‘Lisp function’ above are defined in the default sysout file, resources/lisp1.5.lsp, which will be loaded by default unless you specify another initfile on the command line.

    Functions described as ‘Host function’ are implemented in Clojure, but if you’re brave you can redefine them in Lisp and the Lisp definitions will take precedence over the Clojure implementations.

    -

    Architectural plan

    +

    Architectural plan

    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

    +

    resources/lisp1.5.lsp

    The objective is to have within resources/lisp1.5.lsp, all those functions defined in the Lisp 1.5 Programmer’s Manual which can be implemented in Lisp.

    This means that, while Beowulf is hosted on Clojure, all that would be required to rehost Lisp 1.5 on a different platform would be to reimplement

      -
    • bootstrap.clj
    • -
    • host.clj
    • -
    • read.clj
    • +
    • bootstrap.clj
    • +
    • host.clj
    • +
    • read.clj

    The objective this is to make it fairly easy to implement Lisp 1.5 on top of any of the many Make A Lisp implementations.

    -

    beowulf/boostrap.clj

    +

    beowulf/boostrap.clj

    This file is essentially 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, to bootstrap the full Lisp 1.5 interpreter.

    In addition it contains the function INTEROP, which allows host language functions to be called from Lisp.

    -

    beowulf/host.clj

    +

    beowulf/host.clj

    This file 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/read.clj

    +

    beowulf/read.clj

    This file 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. -
    3. 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.
    4. +
    5. 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;
    6. +
    7. 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.
    -

    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.

    +

    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

    +

    Installation

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

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

    Or clone the source and build it using:

    -
        lein uberjar`
    +
        lein uberjar`
     

    To build it you will require to have Leiningen installed.

    -

    Input/output

    +

    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.

    -

    SYSOUT

    +

    SYSOUT

    SYSOUT dumps the global object list to disk as a single S Expression (specifically: an association list). This allows you to persist your session, with all your current work, to disk. The function takes one argument, expected to be a symbol, and, if that argument is provided, writes a file whose name is that symbol with .lsp appended. If no argument is provided, it will construct a filename comprising the token Sysout, followed by the current date, followed by .lsp. In either case the file will be written to the directory given in the FILEPATH argument at startup time, or by default the current directory.

    Obviously, SYSOUT may be called interactively (and this is the expected practice).

    -

    SYSIN

    -

    SYSIN reads a file from disk and overwrites the global object list with its contents. The expected practice is that this will be a file created by SYSOUT. A command line flag --read is provided so that you can specify

    -

    Learning Lisp 1.5

    +

    SYSIN

    +

    SYSIN reads a file from disk and overwrites the global object list with its contents. The expected practice is that this will be a file created by SYSOUT. A command line flag --read is provided so that you can specify

    +

    Learning Lisp 1.5

    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

    +

    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

    +

    Other implementations

    There’s an online (browser native) Lisp 1.5 implementation here (source code here). It even has a working compiler!

    -

    History resources

    +

    History resources

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

    -

    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 +

    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 a4cedae..16334dd 100644 --- a/docs/codox/mexpr.html +++ b/docs/codox/mexpr.html @@ -1,16 +1,16 @@ -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.

    Consequently, the Beowulf parser can parse the M-Expression grammar as stated in the manual, and generate S-Expressions from it according to the table specified on page 10 of the manual.

    There are two problems with this.

    -

    Problems with interpreting M-Expressions

    -

    Generating idiomatic Lisp

    +

    Problems with interpreting M-Expressions

    +

    Generating idiomatic Lisp

    In the M-Expression notation, a lower case character or sequence of characters represents a variable; an upper case character represents a constant. As the manual says,

    -

    2 . The obvious translation of letting a constant translate into itself will not work. Since the translation of x is X, the translation of X must be something else to avoid ambiguity. The solution is to quote it. Thus X is translated into (QUOTE X).

    +

    2 . The obvious translation of letting a constant translate into itself will not work. Since the translation of x is X, the translation of X must be something else to avoid ambiguity. The solution is to quote it. Thus X is translated into (QUOTE X).

    Thus, necessarily, the translation of a constant must always be quoted. In practice, key constants in Lisp such as T are bound to themselves, so it is idiomatic in Lisp, certainly in the way we have learned to use it, to write, for example,

    (SET (QUOTE NULL) 
    @@ -32,11 +32,12 @@
     

    Is the value of NIL the atom NIL, or is it the empty list ()? If the former, then the translation from the M-Expression above is correct. However, that means that recursive functions which recurse down a list seeking the end will fail. So the latter must be the case.

    NULL is described thus (Ibid, p11):

    -

    This is a predicate useful for deciding when a list is exhausted. It is true if and only if its argument is NIL.

    +

    This is a predicate useful for deciding when a list is exhausted. It is true if and only if its argument is NIL.

    NIL is used explicitly in an M-Expression for example in the definition of intersection (Ibid, p15).

    I think there is an ambiguity in referencing constants which are not bound to themselves in the M-Expression notation as given in the manual. This is particularly problematic with regards to NIL and F, but there may be others instances.

    However, so long as F is bound to NIL, and NIL is also bound to NIL (both of which are true by default, although changeable by the user), and NIL is the special marker used in the CDR of the last cons cell of a flat list, this is a difference which in practice does not make a difference. I still find it worrying, though, that rebinding variables could lead to disaster.

    -

    Curly braces

    +

    Curly braces

    The use of curly braces is not defined in the grammar as stated on page 10. They are not used in the initial definition of APPLY on page 13, but they are used in the more developed restatement on page 70. I believe they are to be read as indicating a section of assembly code to be assembled by the Lisp Assembly Program – but I don’t find the exposition here particularly clear and I’m not sure of this.

    -

    Consequently, the M-Expression interpreter in Beowulf does not interpret curly braces.

    \ No newline at end of file +

    Consequently, the M-Expression interpreter in Beowulf does not interpret curly braces.

    +
    \ No newline at end of file diff --git a/docs/codox/values.html b/docs/codox/values.html index 0cfcf99..d156cd7 100644 --- a/docs/codox/values.html +++ b/docs/codox/values.html @@ -1,27 +1,29 @@ -The properties of the system, and their values

    The properties of the system, and their values

    -

    here be dragons

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

    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’).

    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

    -

    Lisp was originally written on an IBM 704 computer at Massachusetts Institute of Technology, almost seventy years ago.

    +

    History

    +

    Lisp was originally written on an IBM 704 computer at Massachusetts Institute of Technology, almost seventy years ago.

    The machine had registers which were not eight, or sixteen, or thirty two, or sixty four, bits wide, or any other number which would seem rational to modern computer scientists, but thirty six. Myth - folk memory - tells us that the machine’s memory was arranged in pages. As I understand it (but this truly is folk memory) the offset within the page of the word to be fetched was known as the ‘decrement’, while the serial number of the page in the addressing sequence was known as the ‘address’. To fetch a word from memory, you first had to select the page using the ‘address’, and secondly the word itself using the ‘decrement’. So there were specific instructions for selecting the address, and the decrement, from the register separately.

    There were two mnemonics for the machine instructions used to access the content of these registers, respectively:

    -
    CAR
    -
    -

    Contents of the Address part of Register; and

    -
    CDR
    -
    -

    Contents of the Decrement part of Register.

    +
    CAR
    +
    +

    Contents of the Address part of Register; and

    +
    +
    CDR
    +
    +

    Contents of the Decrement part of Register.

    +

    Is this actually true?

    I think so. If you look at page 80 of the Lisp 1 Programmer’s Manual, you will see this:

    -
    TEN                       (the TEN-Mode is entered)
    +
    TEN                       (the TEN-Mode is entered)
     
     O CAR   (((A,B),C)) () \
                             |
    @@ -38,23 +40,23 @@ O14 (read lines O and 1)
     

    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.

    +

    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.

    +

    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

    +

    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

    -

    Grey Anatomy

    -

    The Object List

    +

    Grey Anatomy

    +

    The Object List

    Lisp keeps track of values by associating them with names. It does so by having what is in effect a global registry of all the names it knows to which values are attached. This being a list processing language, that was of course, in early Lisps, a list: a single specialised first class list known as the ‘object list’, or oblist for short.

    -

    Of course, a list need not just be a list of single items, it can be a list of pairs: it can be a list of pairs of the form (name . value). Hold onto that, because I want to talk about another fundamental part of a working Lisp system, the stack.

    -

    The Stack

    +

    Of course, a list need not just be a list of single items, it can be a list of pairs: it can be a list of pairs of the form (name . value). Hold onto that, because I want to talk about another fundamental part of a working Lisp system, the stack.

    +

    The Stack

    Considering the case of pure interpreter first, let’s think about how a function keeps track of the data it’s working on. In order to do its work, it probably calls other functions, to which it passes off data, and they in turn probably call further functions. So, when control returns to our first function, how does it know where its data is? The answer is that each function pushes its argument bindings onto the stack when it starts work, and pops them off again when it exits. So when control returns to a function, its own data is still on the top of the stack. Or, to be precise, actually it doesn’t; in practice the function EVAL does it for each function in turn. But it doesn’t matter: it gets done.

    What is this stack? Well, it’s a list of (name . value) pairs. At least, it is in pure Lisps; Clojure, because it runs on the Java Virtual Machine and interoperates with other software running on the JVM, uses the JVM stack which is a permanently reserved vector of memory never used for anything else. Consequently it cannot be very large; and the consequence of that is that it’s very easy to crash JVM programs because they’ve run out of stack space.

    The advantage of organising your stack as a vector is that on average it’s usually slightly more memory efficient, and that it’s somewhat faster to access. The disadvantage is you need a contiguous block of memory for it, and once you’ve run out, you’ve at best lost both those advantages but in the normal case your program just crashes. Also, the memory you’ve reserved for the stack isn’t available for any other use, even during the most of the time that the stack isn’t using most of it. So of course there’s a temptation to keep the amount reserved for the stack as small as possible.

    @@ -62,7 +64,7 @@ O14 (read lines O and 1)

    The advantage of organising your stack as a list is that, while there is any memory left on the machine at all, you cannot run out of stack.

    ### The Spine

    So, there’s an object list where you associate names and values, and there’s a stack where you associate names and values. But, why do they have to be different? And why do you have to search in two places to find the value of a name?

    -

    The answer is – or it was, and arguably it should be – that you don’t. The stack can simply be pushed onto the front of the object list. This has multiple advantages. The first and most obvious is that you only have to search in one place for the value associated with a name.

    +

    The answer is – or it was, and arguably it should be – that you don’t. The stack can simply be pushed onto the front of the object list. This has multiple advantages. The first and most obvious is that you only have to search in one place for the value associated with a name.

    The second is more subtle: a function can mask a variable in the object list by binding the same name to a new value, and the functions to which it then calls will only see that new value. This is useful if, for example, printed output is usually sent to the user’s terminal, but for a particular operation you want to send it to a line printer or to a file on disk. You simply rebind the name of the standard output stream to your chosen output stream, and call the function whose output you want to redirect.

    So, in summary, there’s a lot of merit in making the stack and the object list into a single central structure on which the architecture of our Lisp system is built. But there’s more we need to record, and it’s important.

    ### Fields and Properties

    @@ -72,35 +74,35 @@ O14 (read lines O and 1)

    But if instead of storing a table for each sort of thing on which we hold data, and a row in that table for each item of that sort on which we store data, we simply tagged each thing on which we hold data with those things which are interesting about them? We could tag my friend Lucy with the fact she’s on pilgrimage, and what her pilgrimage route is. Those aren’t things we need to know about most people, it would be absurdly wasteful to add a column to a person table to record pilgrimage route. So in a conventional data system we would lose that data.

    Lisp has had, right back from the days of Lisp 1.5 – so, for sixty-five years – a different solution. We can give every symbol arbitrarily many, arbitrarily different, properties. A property is a (name . value) pair. We don’t have to store the same properties for every object. The values of the properties don’t have to have a fixed size, and they don’t have to take up space they don’t need. It’s like having a table with as many fields as we choose, and being able to add more fields at any time.

    So, in summary, I knew, in building Beowulf, that I’d have to implement property lists. I just didn’t know how I was going to do it.

    -

    Archaeology

    +

    Archaeology

    What I’m doing with Beowulf is trying to better understand the history of Lisp by reconstructing a very early example; in this case, Lisp 1.5, from about 1962, or sixty one years ago.

    I had had the naive assumption that entries on the object list in early Lisps had their CAR pointing to the symbol and their CDR pointing to the related value. Consequently, in building beowulf, I could not work out where the property list went. More careful reading of the text implies, but does not explicitly state, that my naive assumption is wrong.

    Instead, it appears that the CAR points to the symbol, as expected, but the CDR points to the property list; and that on the property list there are privileged properties at least as follows:

    -
    APVAL
    -
    the simple straightforward ordinary value of the symbol, considered as a variable;
    -
    EXPR
    -
    the definition of the function considered as a normal lambda expression (arguments to be evaluated before applying);
    -
    FEXPR
    -
    the definition of a function which should be applied to unevaluated arguments (what InterLisp and Portable Standard Lisp would call nlambda);
    -
    SUBR
    -
    the definition of a compiled subroutine which should be applied to evaluated arguments;
    -
    FSUBR
    -
    the definition of a compiled subroutine which should be applied to unevaluated arguments.
    +
    APVAL
    +
    the simple straightforward ordinary value of the symbol, considered as a variable;
    +
    EXPR
    +
    the definition of the function considered as a normal lambda expression (arguments to be evaluated before applying);
    +
    FEXPR
    +
    the definition of a function which should be applied to unevaluated arguments (what InterLisp and Portable Standard Lisp would call nlambda);
    +
    SUBR
    +
    the definition of a compiled subroutine which should be applied to evaluated arguments;
    +
    FSUBR
    +
    the definition of a compiled subroutine which should be applied to unevaluated arguments.

    I think there was also another privileged property value which contained the property considered as a constant, but I haven’t yet confirmed that.

    From this it would seem that Lisp 1.5 was not merely a ‘Lisp 2’ but in fact a ‘Lisp 6’, with six effectively first class namespaces. In fact it’s not as bad as that, because of the way EVAL is evaluated.

    Essentially the properties are tried in turn, and only the first value found is used. Thus the heirarchy is

      -
    1. APVAL
    2. -
    3. EXPR
    4. -
    5. FEXPR
    6. -
    7. SUBR
    8. -
    9. FSUBR
    10. +
    11. APVAL
    12. +
    13. EXPR
    14. +
    15. FEXPR
    16. +
    17. SUBR
    18. +
    19. FSUBR

    This means that, while the other potential values can be retrieved from the property list, interpreted definitions (if present) will always be preferred to uninterpreted definitions, and lambda function definitions (which evaluate their arguments), where present, will always be preferred to non-lamda definitions, which don’t.

    BUT NOTE THAT the APVAL value is sought only when seeking a variable value for the symbol, while the others are only when seeking a function value, so Lisp 1.5 is a ‘Lisp 2’, not a ‘Lisp 1’. I strongly believe that this is wrong: a function is a value, and should be treated as such. But at the same time I do acknowledge the benefit of being able to store both source and compiled forms of the function as properties of the same symbol.

    -

    The persistent problem

    +

    The persistent problem

    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?

    @@ -108,50 +110,50 @@ O14 (read lines O and 1)

    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. +
    5. 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.
    6. +
    7. To implement PUT and GET in Lisp, and have them destructively modify the working copy of the object list.

    Neither of these particularly appeal.

    -

    How property lists should work

    -

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

    -

    List format

    -

    Firstly, are they association lists comprising dotted pairs of (property-name . value), i.e.:

    +

    How property lists should work

    +

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

    +

    List format

    +

    Firstly, are they association lists comprising dotted pairs of (property-name . value), i.e.:

    -

    ((property-name1 . value1) (property-name2 . value2) … (property-namen . valuen))

    +

    ((property-name1 . value1) (property-name2 . value2) … (property-namen . valuen))

    I have assumed so, and that is what I presently intend to implement, but the diagrams on pages 59 and 60 seem rather to show a flat list of interleaved names and values:

    -

    (property-name1 value1 property-name2 value2 … property-namen valuen)

    +

    (property-name1 value1 property-name2 value2 … property-namen valuen)

    I cannot see what the benefit of this latter arrangement is, and I’m unwilling to do it, although I think it may be what was done. But if it was done that way, why was it done that way? These were bright people, and they certainly knew about association lists. So… I’m puzzled.

    -

    Function signatures

    +

    Function signatures

    To associate the value of a property with a symbol, we need three things: we need the symbol, we need the property name, and we need the value. For this reason, Portable Standard Lisp and others has a function put with three arguments:

    -

    (Put U:id IND:id PROP:any): any The indicator IND with the property PROP is placed on the property list of the id U. If the action of Put occurs, the value of PROP is returned. If either of U and IND are not ids the type mismatch error occurs and no property is placed. (Put 'Jim 'Height 68) The above returns 68 and places (Height . 68) on the property list of the id Jim

    +

    (Put U:id IND:id PROP:any): any The indicator IND with the property PROP is placed on the property list of the id U. If the action of Put occurs, the value of PROP is returned. If either of U and IND are not ids the type mismatch error occurs and no property is placed. (Put 'Jim 'Height 68) The above returns 68 and places (Height . 68) on the property list of the id Jim

    Cambridge Lisp is identical to this except in lower case. InterLisp and several others have putprop:

    -

    (PUTPROP ATM PROP VAL) [Function] Puts the property PROP with value VAL on the property list of ATM. VAL replaces any previous value for the property PROP on this property list. Returns VAL.

    +

    (PUTPROP ATM PROP VAL) [Function] Puts the property PROP with value VAL on the property list of ATM. VAL replaces any previous value for the property PROP on this property list. Returns VAL.

    The execrable Common Lisp uses its execrable macro setf but really the less said about that the better.

    -

    So I was looking for a function of three arguments to set properties, and I didn’t find one.

    +

    So I was looking for a function of three arguments to set properties, and I didn’t find one.

    There’s a function DEFINE which takes one argument, an association list of pairs:

    -
    	(function-name . function-definition)`
    +
    	(function-name . function-definition)`
     

    So how does that work, if what it’s doing is setting properties? If all you’re passing is pairs of name and definition, where does the property name come from?

    The answer is as follows, taken from the manual:

    -

    define [x] : EXPR pseudo-function

    -

    The argument of define, x, is a list of pairs

    -
    -

    ((ul vl) (u2 v2) … (un vn))

    -
    -

    where each u is a name and each v is a λ-expression for a function . For each pair, define puts an EXPR on the property list for u pointing to v. The function of define puts things on at the front of the property list. The value of define is the list of us.

    +

    define x : EXPR pseudo-function

    +

    The argument of define, x, is a list of pairs

    +
    +

    ((ul vl) (u2 v2) … (un vn))

    +
    +

    where each u is a name and each v is a λ-expression for a function . For each pair, define puts an EXPR on the property list for u pointing to v. The function of define puts things on at the front of the property list. The value of define is the list of us.

    So, in fact, the value of the property being set by define is fixed: hard wired, not parameterised. That seems an astonishing decision, until you realise that Lisp 1.5’s creators weren’t creating their functions one by one, in a playful exploration with their system, but entering them in a batch.

    -

    Learning by doing

    +

    Learning by doing

    In fact, when I got over my surprise, I realised that that (name . function-definition) list is actually very much like this, which is an excerpt from a sysout from a Beowulf prototype:

    -
    (...
    +
    (...
     	(MAPLIST LAMBDA (L F) 
                (COND ((NULL L) NIL) 
                      ((QUOTE T) (CONS (F (CAR L)) (MAPLIST (CDR L) F)))))
    @@ -172,81 +174,45 @@ O14 (read lines O and 1)
     

    Because the point of a sysout is you don’t write it. The point about the REPL – the Read Eval Print Loop which is the heart of the interactive Lisp development cycle, where you sit playing with things and fiddling with them interactively, and where when one thing works you get onto the next without bothering to make some special effort to record it.

    The point of a sysout is that, at the end of the working day, you invoke one function

    - - - - - - - - - - - - - - - - - - + + + + + +
    Function Type Signature Implementation Documentation
    SYSOUT Host function (SYSOUT); (SYSOUT FILEPATH) SUBR 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.
    Function Type Signature Implementation Documentation
    SYSOUT Host function (SYSOUT); (SYSOUT FILEPATH) SUBR 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.

    At the start of the next working day, you load that sysout in and continue your session.

    The sysout captures the entire working state of the machine. No-one types it in, as an operation in itself. Instead, data structures – corpuses of functions among them – simply build up on the object list almost casually, as a side effect of the fact that you’re enjoying exploring your problem and finding elegant ways of solving it. So SYSOUT and SYSIN seem to me, as someone who all his adult life has worked with Lisp interactively, as just an automatic part of the cycle of the day.

    -

    The process of discovery

    -

    The thing is, I don’t think anyone is ever going to use Beowulf the way Lisp 1.5 was used. I mean, probably, no one is ever going to use Beowulf at all; but if they did they wouldn’t use Beowulf the way Lisp 1.5 was used.

    +

    The process of discovery

    +

    The thing is, I don’t think anyone is ever going to use Beowulf the way Lisp 1.5 was used. I mean, probably, no one is ever going to use Beowulf at all; but if they did they wouldn’t use Beowulf the way Lisp 1.5 was used.

    I’m a second generation software person. I have worked, in my career, with two people who personally knew and had worked with Alan Turing. I have worked with, and to an extent been mentored by, Chris Burton, who in his apprenticeship was part of the team that built the Manchester Mark One, and who in his retirement led the team who restored it. But I never knew the working conditions they were accustomed to. In my first year at university we used card punches, and, later, when we had a bit of seniority, teletypewriters (yes, that’s what TTY stands for), but by the time I’d completed my undergraduate degree and become a research associate I had a Xerox 1108 workstation with a huge bitmapped graphic screen, and an optical mouse, goddamit, running InterLisp, all to myself.

    People in the heroic age did not have computers all to themselves. They did not have terminals all to themselves. They didn’t sit at a terminal experimenting in the REPL. They wrote their algorithms in pencil on paper. When they were certain they’d got it right, they’d use a card punch to punch a deck of cards carrying the text of the program, and then they were certain they’d got that right, they’d drop it into the input hopper. Some time later their batch would run, and the operator would put the consequent printout into their pigeon hole for them to collect.

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

    +

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

    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.

    +

    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?

    @@ -254,10 +220,11 @@ O14 (read lines O and 1)

    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.

    +

    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. 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 diff --git a/project.clj b/project.clj index 20483ff..64742f2 100644 --- a/project.clj +++ b/project.clj @@ -19,11 +19,12 @@ [environ "1.2.0"] [instaparse "1.4.12"] [org.jline/jline "3.23.0"] - [rhizome "0.2.9"] ;; not needed in production builds + [com.github.seancorfield/expectations "2.0.165"] + ;; [rhizome "0.2.9"] ;; not needed in production builds ] :main beowulf.core :plugins [[lein-cloverage "1.2.2"] - [lein-codox "0.10.7"] + [lein-codox "0.10.8"] [lein-environ "1.1.0"]] :profiles {:jar {:aot :all} :uberjar {:aot :all} diff --git a/src/beowulf/host.clj b/src/beowulf/host.clj index 56fae9a..81e17ba 100644 --- a/src/beowulf/host.clj +++ b/src/beowulf/host.clj @@ -441,7 +441,7 @@ recurse down the list two entries at a time to avoid confusing names with values." [target plist] - (if (and (instance? ConsCell plist)(even? (count plist))) + (if (and (instance? ConsCell plist) (even? (count plist))) (cond (= plist NIL) NIL (= (first plist) target) plist :else (hit-or-miss-assoc target (CDDR plist))) @@ -516,9 +516,10 @@ `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." [a-list indicator] - (map - #(PUT (CAR %) indicator (CDR %)) - a-list)) + (doall + (map + #(when (PUT (CAR %) indicator (CDR %)) (CAR %)) + a-list))) (defn DEFINE "Bootstrap-only version of `DEFINE` which, post boostrap, can be overwritten diff --git a/test/beowulf/host_test.clj b/test/beowulf/host_test.clj index 5f73ea8..4d43b1e 100644 --- a/test/beowulf/host_test.clj +++ b/test/beowulf/host_test.clj @@ -1,11 +1,14 @@ (ns beowulf.host-test - (:require [beowulf.cons-cell :refer [F make-beowulf-list T]] - [beowulf.host :refer [CDR DIFFERENCE GENSYM GET NUMBERP PLUS PUT - RPLACA RPLACD TIMES]] + (:require [beowulf.cons-cell :refer [F make-beowulf-list make-cons-cell T]] + [beowulf.host :refer [ADD1 AND CADDDR CAR CDR DEFINE DIFFERENCE + ERROR FIXP GREATERP lax? LESSP NILP NULL + NUMBERP OR PLUS RPLACA RPLACD SUB1 TIMES uaf]] [beowulf.io :refer [SYSIN]] - [beowulf.oblist :refer [NIL]] + [beowulf.oblist :refer [*options* NIL]] [beowulf.read :refer [gsp]] - [clojure.test :refer [deftest is testing use-fixtures]])) + [clojure.test :refer [deftest is testing use-fixtures]] + [expectations.clojure.test + :refer [defexpect expect more-> more-of]])) (use-fixtures :once (fn [f] (try (when (SYSIN "resources/lisp1.5.lsp") @@ -20,31 +23,44 @@ (deftest destructive-change-test (testing "RPLACA" (let - [l (make-beowulf-list '(A B C D E)) - target (CDR l) - expected "(A F C D E)" - actual (do (RPLACA target 'F) (print-str l))] + [l (make-beowulf-list '(A B C D E)) + target (CDR l) + expected "(A F C D E)" + actual (do (RPLACA target 'F) (print-str l))] (is (= actual expected))) (is (thrown-with-msg? - Exception - #"Un-ġefōg þing in RPLACA.*" - (RPLACA (make-beowulf-list '(A B C D E)) "F")) + Exception + #"Un-ġefōg þing 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.*" - (RPLACA '(A B C D E) 'F)) - "You can't RPLACA into anything which isn't a MutableSequence.") - ) - (testing "RPLACA" + Exception + #"Uncynlic miercels in RPLACA.*" + (RPLACA '(A B C D E) 'F)) + "You can't RPLACA into anything which isn't a MutableSequence.")) + (testing "RPLACD" (let - [l (make-beowulf-list '(A B C D E)) - target (CDR l) - expected "(A B . F)" - actual (do (RPLACD target 'F) (print-str l))] + [l (make-beowulf-list '(A B C D E)) + target (CDR l) + expected "(A B . F)" + actual (do (RPLACD target 'F) (print-str l))] (is (= actual expected))) - ) - ) + (let + [l (make-beowulf-list '(A B C D E)) + target (CDR l) + expected "(A B)" + actual (do (RPLACD target NIL) (print-str l))] + (is (= actual expected))) + (is (thrown-with-msg? + Exception + #"Un-ġefōg þing in RPLACD.*" + (RPLACD (make-beowulf-list '(A B C D E)) :a)) + "You can't represent a keyword in Lisp 1.5") + (is (thrown-with-msg? + Exception + #"Uncynlic miercels in RPLACD.*" + (RPLACD "ABCDE" 'F)) + "You can't RPLACD into anything which isn't a MutableSequence."))) (deftest numberp-tests (testing "NUMBERP" @@ -71,13 +87,171 @@ (let [expected 3.5 actual (PLUS 1.25 9/4)] (is (= actual expected)) + (is (float? actual))) + (let [expected 3.5 + actual (PLUS -2.5 6)] + (is (= actual expected) "Negative numbers are cool.") (is (float? actual)))) (testing "TIMES" (let [expected 6 actual (TIMES 2 3)] + (is (= actual expected))) + (let [expected 2.5 + actual (TIMES 5 0.5)] (is (= actual expected)))) (testing "DIFFERENCE" (let [expected -1 actual (DIFFERENCE 1 2)] + (is (= actual expected))) + (let [expected (float 0.1) + actual (DIFFERENCE -0.1 -0.2)] + (is (= actual expected)))) + (testing "ADD1" + (let [expected -1 + actual (ADD1 -2)] + (is (= actual expected))) + (let [expected (float 3.5) + actual (ADD1 2.5)] + (is (= actual expected)))) + (testing "SUB1" + (let [expected -3 + actual (SUB1 -2)] + (is (= actual expected))) + (let [expected (float 1.5) + actual (SUB1 2.5)] (is (= actual expected))))) +(deftest laxness + (testing "lax" + (let [expected true + actual (lax? 'Test)] + (is (= actual expected) "Pass, the Queen's Cat, and all's well"))) + (testing "strict" + (binding [*options* (assoc *options* :strict true)] + (is (thrown-with-msg? Exception #".*ne āfand innan Lisp 1.5" (lax? 'Test)))))) + +(deftest access-tests + (testing "primitive access" + (let [cell (make-cons-cell 1 7)] + (let [expected 1 + actual (CAR cell)] + (is (= actual expected))) + (let [expected 7 + actual (CDR cell)] + (is (= actual expected)))) + (is (thrown-with-msg? Exception #".*Ne can tace CAR of.*" (CAR 7))) + (is (thrown-with-msg? Exception #".*Ne can tace CDR of.*" (CDR 'A))) + (is (thrown-with-msg? Exception #".*Ne liste.*" (CADDDR "Foo"))) + (is (thrown-with-msg? Exception #".*uaf: unexpected letter in path.*" + (uaf (make-beowulf-list '(A B C D)) + '(\d \a \z \e \d)))))) + +(deftest misc-predicate-tests + (testing "NULL" + (let [expected T + actual (NULL NIL)] + (is (= actual expected))) + (let [expected F + actual (NULL (make-beowulf-list '(A B C)))] + (is (= actual expected)))) + (testing "NILP" + (let [expected T + actual (NILP NIL)] + (is (= actual expected))) + (let [expected NIL + actual (NILP (make-beowulf-list '(A B C)))] + (is (= actual expected)))) + (testing "AND" + (let [expected T + actual (AND)] + (is (= actual expected))) + (let [expected T + actual (AND T T)] + (is (= actual expected))) + (let [expected T + actual (AND T T T)] + (is (= actual expected))) + (let [expected T + actual (AND 1 'A (make-beowulf-list '(A B C)))] + (is (= actual expected))) + (let [expected F + actual (AND NIL)] + (is (= actual expected))) + (let [expected F + actual (AND T T F T)] + (is (= actual expected)))) + (testing "OR" + (let [expected F + actual (OR)] + (is (= actual expected))) + (let [expected T + actual (OR NIL T)] + (is (= actual expected))) + (let [expected T + actual (OR T F T)] + (is (= actual expected))) + (let [expected T + actual (OR 1 F (make-beowulf-list '(A B C)))] + (is (= actual expected))) + (let [expected F + actual (OR NIL)] + (is (= actual expected))) + (let [expected F + actual (OR NIL F)] + (is (= actual expected)))) + (testing "FIXP" + (let [expected F + actual (FIXP NIL)] + (is (= actual expected))) + (let [expected F + actual (FIXP 'A)] + (is (= actual expected))) + (let [expected F + actual (FIXP 3.2)] + (is (= actual expected))) + (let [expected T + actual (FIXP 7)] + (is (= actual expected)))) + (testing "LESSP" + (let [expected F + actual (LESSP 7 3)] + (is (= actual expected))) + (let [expected T + actual (LESSP -7 3.5)] + (is (= actual expected))) + (let [expected F + actual (LESSP 3.14 3.14)] + (is (= actual expected)))) + (testing "GREATERP" + (let [expected T + actual (GREATERP 7 3)] + (is (= actual expected))) + (let [expected F + actual (GREATERP -7 3.5)] + (is (= actual expected))) + (let [expected F + actual (GREATERP 3.14 3.14)] + (is (= actual expected))))) + +;; Really tricky to get DEFINE set up for testing here. It works OK in the +;; REPL, but there's nonsense going on with lazy sequences. Better to +;; reimplement in Lisp. +;; (deftest define-tests +;; (testing "DEFINE" +;; (let [expected "(FF)" +;; actual (str (doall (DEFINE +;; (gsp "((FF LAMBDA (X) (COND ((ATOM X) X) (T (FF (CAR X))))))"))))] +;; (is (= actual expected))))) + +(defexpect error-without-code + (expect (more-> clojure.lang.ExceptionInfo type + (more-of {:keys [:phase :function :args :type :code]} + 'A1 code) ex-data) + (ERROR))) + +(defexpect error-with-code + (let [x 'X1] + (expect (more-> clojure.lang.ExceptionInfo type + (more-of {:keys [:phase :function :args :type :code]} + x code) ex-data) + (ERROR x))))