(rontolisp) docs

セルフホスティング REPL

readevalprint はすべてのバックエンドで利用できるため、REPL を RontoLisp 自身で記述し、スタンドアロンの .class.wasm にコンパイルできます。

例(repl.lisp):

(princ "> ")
(setq form (read))
(while form
  (print (eval form))
  (princ "> ")
  (setq form (read)))
rontolisp repl.lisp               # interpret
rontolisp repl.lisp -o repl.class
java repl                                                                  # REPL on the JVM
rontolisp repl.lisp -o repl.wasm
wasmtime run -W gc repl.wasm                                               # REPL on WASM
> (defun square (x) (* x x))
square
> (mapcar #'square '(1 2 3))
(1 4 9)
> (- 5)
-5

read は EOF で nil を返すため、ループは Ctrl-D で終了します(nil() を入力しても終了します)。プロンプトで入力された各フォームはランタイムのリーダーで解析され、組み込みの eval ランタイムで評価されるため、コンパイルされた eval の制限コンパイルされた read/load の制限 が適用されます。