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