Fixed up readme.
[scheme.forth.jl.git] / README.md
1 scheme.forth.jl
2 ---------------
3
4 A hobby Scheme interpreter for FORTH 83. Specifically it is targeted at
5 [forth.jl](http://github.com/tgvaughan/forth.jl) which is an implementation of
6 FORTH on top of [Julia](http://www.julialang.org), hence the name.  It began
7 life as a fairly direct port of Peter Micheaux's [Bootstrap
8 Scheme](https://github.com/petermichaux/bootstrap-scheme) (as described in
9 [this wonderful series of blog
10 posts](http://peter.michaux.ca/articles/scheme-from-scratch-introduction)) from
11 C to forth, but also includes:
12
13 * variadic compound function support,
14 * pre-evaluation syntactic analysis,
15 * mark-sweep garbage collection,
16 * quasiquotation,
17 * a basic (non-hygienic) macro system and
18 * first-class continuations via `call-with-current-continuation`.
19
20 In future, I plan to also implement a more complete numerical tower to
21 bring it closer to [R5RS](http://www.schemers.org/Documents/Standards/R5RS/).
22
23 The goal is for the interpreter to be complete enough to be used to complete
24 the majority of the exercises found in [SICP](http://sarabander.github.io/sicp/).
25
26 Running the interpreter
27 =======================
28
29 To run this Scheme interpreter, first open Julia (**version >=0.6**) from the src
30 directory contained in this repository.  If you've not done so already, install
31 forth.jl using the following command:
32
33     julia> Pkg.clone("https://github.com/tgvaughan/forth.jl")
34
35 Then, import and run the Forth system:
36
37     julia> import forth
38     julia> forth.run()
39     Welcome to forth.jl!
40
41 Once Forth is running, execute the Scheme source and fire up the
42 REPL using the following commands:
43
44     include scheme.4th  ok
45     scheme repl
46     Welcome to scheme.forth.jl!
47     Use Ctrl-D to exit.
48
49     >
50
51 At this point you can start entering Scheme commands.  For example,
52
53     > (define (factorial n)
54         (if (= n 0)
55           1
56           (* n (factorial (- n 1)))))
57     ; ok
58     > (factorial 5)
59     ; 120
60
61 Metacircular Evaluator
62 ======================
63
64 Of course, one of the things you can do in Scheme (or of course any programming
65 language, this is the fundamental thing) is implement an interpreter for
66 another programming language.  The examples directory in this repository
67 contains a verbatim copy of the source for the "metacircular" scheme interpreter
68 from SICP. To load it, use the following command:
69
70     > (load "../examples/metacirc.scm")
71     ; ok
72
73 Be prepared to wait a couple of minutes. When the interpreter finally loads, enter
74 the following command to run it:
75
76     > (driver-loop)
77
78 You'll then be greeted by the following prompt:
79
80     ;; M-Eval input:
81
82 At this point you can start entering Scheme commands... but be prepared to wait
83 a while for each result.  After all, when evaluating commands in the MCE you are
84 running a program in a Scheme interpreter running inside another Scheme
85 interpreter which is itself running on a Forth system that is implemented atop
86 a virtual register machine running in the Julia numerical computing
87 environment.  **That's four levels of abstraction more than a native Julia
88 program experiences**, so some delay is to be expected!
89
90 For instance, the following example from SICP defines and demonstrates a
91 recursive list append procedure:
92
93     (define (append x y)
94        (if (null? x)
95            y
96            (cons (car x)
97                  (append (cdr x) y))))
98
99      ;;; M-Eval value:
100      ok
101
102      ;;; M-Eval input:
103      (append '(a b c) '(d e f))
104
105      ;;; M-Eval value:
106      (a b c d e f)
107
108 You may have to wait a minute or so for the final result to be printed.
109
110 License
111 =======
112
113 This software is free (as in freedom) and is distributed under the terms
114 of version 3 of the GNU General Public License.  A copy of this license
115 is included in this repository in the file COPYING.