V のための Lisp。末尾呼び出しは本当に無料

明示的な CEK マシン上の小さな Lisp 方言です。末尾位置の呼び出しは新しいフレームを積む代わりに自分のフレームを使い回すので、ループはループであり、死ぬまで膨らむスタックではありません。

ドキュメントを読む ソースコード

この節はまだあなたの言語に翻訳されていないため、英語で表示しています。翻訳を歓迎します。

A taste

(define (fib n)
  (if (< n 2)
      n
      (+ (fib (- n 1))
         (fib (- n 2)))))

(fib 20)          ;=> 6765

この節はまだあなたの言語に翻訳されていないため、英語で表示しています。翻訳を歓迎します。

これは何か

Real tail calls

A quarter of a million iterations end with an empty continuation stack. Mutual recursion tail-calls too, which is the part most trampolines skip.

An explicit machine

Evaluation is a data structure you can inspect, not a recursive function you have to trust. Every step is counted, and every limit is a field you can set.

Embeddable by shape

The machine is a library with no global state. print output is collected into a field, so a host can capture it rather than fight it.

この節はまだあなたの言語に翻訳されていないため、英語で表示しています。翻訳を歓迎します。

Where it stands

Working: the reader, closures, arithmetic, branching, loop, dotimes, letrec, cond, case, and proper tail calls including mutual recursion.

Not yet: let*, rest parameters, callable keywords, modules, and macros. Each one is named in the repository rather than quietly missing.