Added the bones of EVAL; tried to make cons-cell Seqable - failed
This commit is contained in:
parent
9f669d2d50
commit
6853c6c29c
36
README.md
36
README.md
|
@ -2,31 +2,33 @@
|
|||
|
||||
LISP 1.5 is to all Lisp dialects as Beowulf is to Emglish literature.
|
||||
|
||||
## What this is
|
||||
|
||||
A work-in-progress towards an implementation of Lisp 1.5 in Clojure.
|
||||
|
||||
## 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.
|
||||
|
||||
## Installation
|
||||
|
||||
Download from http://example.com/FIXME.
|
||||
|
||||
## Usage
|
||||
|
||||
FIXME: explanation
|
||||
`java -jar beowulf-0.1.0-standalone.jar`
|
||||
|
||||
$ java -jar beowulf-0.1.0-standalone.jar [args]
|
||||
## Learning Lisp 1.5
|
||||
|
||||
## Options
|
||||
|
||||
FIXME: listing of options this app accepts.
|
||||
|
||||
## Examples
|
||||
|
||||
...
|
||||
|
||||
### Bugs
|
||||
|
||||
...
|
||||
|
||||
### Any Other Sections
|
||||
### That You Think
|
||||
### Might be Useful
|
||||
The `Lisp 1.5 Programmer's Manual` is still
|
||||
[in print, ISBN 13 978-0-262-13011-0](https://mitpress.mit.edu/books/lisp-15-programmers-manual); but it's also
|
||||
[available online](http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf).
|
||||
|
||||
## License
|
||||
|
||||
|
|
|
@ -3,7 +3,24 @@
|
|||
|
||||
(def NIL (symbol "NIL"))
|
||||
|
||||
(deftype ConsCell [CAR CDR])
|
||||
(deftype ConsCell [CAR CDR]
|
||||
clojure.lang.ISeq
|
||||
(cons [this x] (ConsCell. x this))
|
||||
(count [this] (if
|
||||
(= (.CDR this) NIL)
|
||||
0
|
||||
(inc (count (.CDR this)))))
|
||||
(first [this] (.CAR this))
|
||||
(more [this] (if
|
||||
(= (.CDR this) NIL)
|
||||
clojure.lang.PersistentList/EMPTY
|
||||
(.CDR this)))
|
||||
(next [this] (.CDR this))
|
||||
(seq [this] this) ;; doesn't work - `Method beowulf/cons_cell/ConsCell.seq()Lclojure/lang/ISeq; is abstract`
|
||||
|
||||
clojure.lang.IPersistentCollection
|
||||
(empty [this] false)
|
||||
(equiv [this other] false))
|
||||
|
||||
(defn make-cons-cell
|
||||
[a d]
|
||||
|
|
25
src/beowulf/eval.clj
Normal file
25
src/beowulf/eval.clj
Normal file
|
@ -0,0 +1,25 @@
|
|||
(ns beowulf.eval
|
||||
(:require [beowulf.cons-cell :refer [make-beowulf-list make-cons-cell NIL]]))
|
||||
|
||||
(declare *oblist* primitive-eval)
|
||||
|
||||
|
||||
|
||||
(defn primitive-eval
|
||||
[x]
|
||||
(cond
|
||||
(number? x) x
|
||||
(symbol? x) (@*oblist* x)
|
||||
(instance? x beowulf.cons_cell.ConsCell)
|
||||
(apply (primitive-eval (.CAR x)) (map primitive-eval (.CDR x)))
|
||||
:else
|
||||
(throw (Exception. (str "Don't know how to eval `" x "`")))))
|
||||
|
||||
|
||||
(def ^:dynamic *oblist*
|
||||
"The base environment."
|
||||
(atom {'NIL NIL
|
||||
'F NIL
|
||||
'T 'T
|
||||
'eval primitive-eval}))
|
||||
|
Loading…
Reference in a new issue