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