back
2 comments
I think it's just manual tail-call optimization?
Why not? map, fold/reduce are not necessarily implemented as the textbook says.
Certainly not. The foldl is a part of the TypeScript program that implements the Lisp.

By the way, as for "while" in the implemented Lisp, it is defined with recursion and will be executed with tail-call optimization. See

  (defmacro while (test &rest body)
    (let ((loop (gensym)))
      `(letrec ((,loop (lambda () (cond (,test ,@body (,loop))))))
         (,loop))))
in the const prelude of lisp.ts (http://www.oki-osk.jp/esc/typescript/lisp/lisp.ts.html).
Thanks for this information.

My point was more that map and reduce do not inherently require a recursive implementation and can be implemented directly as loops.

I don't follow closely TypeScript: is tail-call merging done when compiling to Javascript or is the Javascript runtime responsible for this behavior?

No, neither. That behavior is implemented in the same way as in the Lisp in Dart (http://www.oki-osk.jp/esc/dart/lisp-en.html#4).