Code Monkey home page Code Monkey logo

scheme.forth.jl's Introduction

scheme.forth.jl

A hobby Scheme interpreter for FORTH 83. Specifically it is targeted at forth.jl which is an implementation of FORTH on top of Julia, hence the name. It began life as a fairly direct port of Peter Micheaux's Bootstrap Scheme (as described in this wonderful series of blog posts) from C to forth, but also includes:

  • variadic compound function support,
  • pre-evaluation syntactic analysis,
  • mark-sweep garbage collection,
  • quasiquotation,
  • a basic (non-hygienic) macro system and
  • first-class continuations via call-with-current-continuation.

Running the interpreter

To run this Scheme interpreter, first open Julia (forth.jl requires version >=1.0) from the src directory contained in this repository. If you've not done so already, install forth.jl using the Julia package manager (accessed using the ] key):

(v1.0) pkg> add https://github.com/tgvaughan/forth.jl

Then, import and run the Forth system:

julia> import forth
julia> forth.run()
Welcome to forth.jl!

Once Forth is running, execute the Scheme source and fire up the REPL using the following commands:

include scheme.4th  ok
scheme repl
Welcome to scheme.forth.jl!
Use Ctrl-D to exit.

>

At this point you can start entering Scheme commands. For example,

> (define (factorial n)
    (if (= n 0)
      1
      (* n (factorial (- n 1)))))
; ok
> (factorial 5)
; 120

Metacircular Evaluator

Of course, one of the things you can do in Scheme (or of course any programming language, this is the fundamental thing) is implement an interpreter for another programming language. The examples directory in this repository contains a verbatim copy of the source for the "metacircular" scheme interpreter from SICP. To load it, use the following command:

> (load "../examples/metacirc.scm")
; ok

Be prepared to wait a couple of minutes. When the interpreter finally loads, enter the following command to run it:

> (driver-loop)

You'll then be greeted by the following prompt:

;; M-Eval input:

At this point you can start entering Scheme commands... but be prepared to wait a while for each result. After all, when evaluating commands in the MCE you are running a program in a Scheme interpreter running inside another Scheme interpreter which is itself running on a Forth system that is implemented atop a virtual register machine running in the Julia numerical computing environment. That's four levels of abstraction more than a native Julia program experiences, so some delay is to be expected!

For instance, the following example from SICP defines and demonstrates a recursive list append procedure:

(define (append x y)
   (if (null? x)
       y
       (cons (car x)
             (append (cdr x) y))))

 ;;; M-Eval value:
 ok

 ;;; M-Eval input:
 (append '(a b c) '(d e f))

 ;;; M-Eval value:
 (a b c d e f)

You may have to wait a minute or so for the final result to be printed.

License

This software is free (as in freedom) and is distributed under the terms of version 3 of the GNU General Public License. A copy of this license is included in this repository in the file COPYING.

scheme.forth.jl's People

Contributors

tgvaughan avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.