Scheme.forth.jl: Scheme in Forth in Julia

栏目: IT技术 · 发布时间: 4年前

内容简介:A hobby Scheme interpreter for FORTH 83. Specifically it is targeted atTo run this Scheme interpreter, first open Julia (forth.jl requiresThen, import and run the Forth system:

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:

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.


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

人件(原书第3版)

人件(原书第3版)

[美] Tom DeMarco、[美] Timothy Lister / 肖然、张逸、滕云 / 机械工业出版社 / 2014-8 / 69.00元

在软件管理领域,很少有著作能够与本书媲美。作为经久不衰的畅销书,本书深刻地洞察到软件开发的最大问题不在于技术,而在于人。人的因素并不容易解决,一旦解决了,你将更有可能获得成功。 本书是软件管理领域的传奇经典,被誉为“对美国软件业影响最大的一本书”。全书从管理人力资源、创建健康的办公环境、雇用并留用正确的人、高效团队形成、改造企业文化和快乐工作等多个角度阐释了如何思考和管理软件开发的最大问题—......一起来看看 《人件(原书第3版)》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具