basic implementation of Scheme in InterSystems ObjectScript
Algorithm is taken from http://norvig.com/lispy.html
USER>do ##class(Scheme.Main).repl()
lisp> (define circle-area (lambda (r) (* pi (* r r))))
lisp> (circle-area 3)
28.27433388230813914
lisp> (define fact (lambda (n) (if (<= n 1) 1 (* n (fact (- n 1))))))
lisp> (fact 10)
3628800
lisp> (circle-area (fact 10))
41369087205782.69341
lisp> (define twice (lambda (x) (* 2 x)))
lisp> (define repeat (lambda (f) (lambda (x) (f (f x)))))
lisp> ((repeat twice) 10)
40
lisp> ((repeat (repeat twice)) 10)
160
lisp> ((repeat (repeat (repeat twice))) 10)
2560
lisp>:q
USER>
Supported special forms:
- (quote exp)
- (if test conseq alt)
- (define var exp)
- (set! var exp)
- (lambda (var...) body)
Embedded functions:
- (abs num)
- (car list)
- (cdr list)
- (cons x y)
- (equal? x y)
- (procedure? x)