Tiny Scheme implementation with javascript

description

言語開発合宿で作成した、Scheme(的なもの)のjavascript実装です。

継続と末尾再帰最適化まで実装しました。継続のほうは本当に仕様を満足しているかどうか不安ですが。

マクロは、ありません

詳しい説明はblogのほうに。

features

quote ('expr) , dotted pair( (x . y) ) , comment( ;; ) etc is not supported.

console

hold log

Examples

basic operations

1
(define x 100)
x
(set! x 200)
(list 1 2 3)
(quote (a b c))
(+ 1 2 3)
(- 10 4)
(if (< x 10) "x < 10" "x >= 10")

closure

(define create-counter (lambda (count) (lambda () (set! count (+ count 1)) count)))
(define incr1 (create-counter 0))
(define incr2 (create-counter 100))
(incr1) ;;1
(incr2) ;;101
(incr1) ;;2
(incr1) ;;3
(incr2) ;;102

continuation

(define cc 0)
(list 1 2 (+ (call/cc (lambda (c) (set! cc c) 1)) 2)) ;;(1 2 3)
cc ;; #<continuation>
(cc 0) ;;(1 2 2)
(cc 10) ;;(1 2 12)
(cc 100) ;;(1 2 102)

working with javascript

(js-eval "alert") ;;returns alert function
((js-eval "alert") "hello!") ;;hello!

commands

(long-log 0|1)
verbose log on/off(if on, show middle-level code)
(to-string obj)
apply js toString method to obj
(js-eval js_string)
evaluate string as javascript
(clr)
clear log
_(underscore)
last result

info

this scheme evaluator is based on RKent Dyvbig, Three implementation models for scheme

this program using these libraries:

prototype.js
useful utilities
SimpleTest library in MochiKit
for testing
Gin
js parser generator library with human-readable definition

source: GitHub:todesking/todescheme