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