News for hackers. Stuff that matters.
Re:Open-Source High-quality PDF of SICP by threepointone on Thursday July 26, 2012 @02:00AM (#4294635)
Pardon my ignorance, but why? I haven't read SICP, but I do consider myself to be pretty good at javascript, and was thinking of using it.
Re:Open-Source High-quality PDF of SICP by mjdwitt on Thursday July 26, 2012 @02:28AM (#4294706)
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)
Re:Open-Source High-quality PDF of SICP by ef4 on Thursday July 26, 2012 @10:37AM (#4296142)
TCO is an optimization, it doesn't affect correctness. So you can ignore not having it, until you run out of stack.

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.

Re:Open-Source High-quality PDF of SICP by dspillett on Friday July 27, 2012 @04:01AM (#4300469)
>TCO is an optimization, it doesn't affect correctness. So you can ignore not having it, until you run out of stack.

Correct. Though CPU performance is an issue that tail recursion optimisation addresses too. For simple functions building up the stack frames and deallocating them afterwards can be more work than the function itself. For deep recursion stack space is the problem you usually hit first, but for code with tight performance requirements no always.

>And you certainly won't want to implement Javascript in Javascript.

Oh I don't know, it could be an interesting project if only for an exercise in intellectual onanism!

In fact I've heard of it being done a few times. The first ones that pop up in Google are http://sns.cs.princeton.edu/2012/04/javascript-in-javascript... which is aimed at sand-boxing (and looks like an interesting if not efficient idea) and https://github.com/mozilla/narcissus/ which has the stated goal of being used for experimentation with the language itself (so the fact it is implemented in javascript is probably less relevant).

Re:Open-Source High-quality PDF of SICP by irahul on Thursday July 26, 2012 @02:49AM (#4294758)
> Because javascript lacks this and many other features of Scheme/Lisp, I wouldn't really recommend using it for SICP.

A language without TCO won't affect what you get out of SICP. Just assume JS is tail recursive. The first 3 chapters can be done(with some translation) in JS.

Re:Open-Source High-quality PDF of SICP by threepointone on Thursday July 26, 2012 @02:34AM (#4294726)
I see; that makes sense. Thanks! A good reason to learn scheme.
Re:Open-Source High-quality PDF of SICP by mjdwitt on Thursday July 26, 2012 @02:39AM (#4294740)
Glad I could help. Scheme is great for introducing oneself to many concepts not commonly present or used in more common imperative languages. That, and the SICP is just a ton of fun.
Re:Open-Source High-quality PDF of SICP by jlarocco on Thursday July 26, 2012 @02:32AM (#4294720)
SICP is a book about programming in Scheme, so it heavily uses the features of Scheme.

Most of the concepts covered are applicable outside of Scheme, but if you're going to work through the code, you're better off just using Scheme.

Re:Open-Source High-quality PDF of SICP by threepointone on Thursday July 26, 2012 @07:07AM (#4295395)
Looks like I might just do that. Thank you!