|
|
|
|
|
by mjdwitt
5072 days ago
|
|
TCO refers to tail call optimization, which is a useful optimization for languages such as Scheme which encourage heavy use of recursion. TCO allows the interpreter to reuse the current stack frame when a tail-recursive[1] function calls itself instead of creating a new stack frame for each recursive call. Because javascript lacks this and many other features of Scheme/Lisp, I wouldn't really recommend using it for SICP. [1] Tail recursive functions are recursive functions which merely return the result of their recursive call to the caller instead of further processing those results before returning. In pseudocode: // non-tail
expt(b, x):
if x == 0: 1
else: x * expt(b, x-1)
// tail-recursive
tail-expt(b, x, ans):
if x == 0: ans
else: tail-expt(b, x-1, x*ans)
For these definitions: expt(2, 3) == tail-expt(2, 3, 1)
|
|
There is a much bigger reason to stick with Scheme for SICP: all the meta-circular evaluator stuff where you learn to implement Scheme in Scheme. I supposed you could implement Scheme in Javascript, but then you'd still need to learn Scheme. And you certainly won't want to implement Javascript in Javascript.