jason.orendorff at gmail.com
Fri Aug 15 09:25:21 PDT 2008
On Fri, Aug 15, 2008 at 12:22 AM, Michael Haufe <TNO at thenewobjective.com> wrote:
> I apologize if this issue was discussed already, I've been unable to
> find an answer after a few hours of digging and Googling.
> I was watching some old SICP videos and translating some of the code
> couple of errors when implementing Peano Arithmetic.
I think it's a case of mistranslation. When Scheme says (+ x 1), the
right ECMAScript translation is x + 1, not x++. So, in your examples:
> return add2(x--,y++); //recursion error
return add2(x - 1, y + 1);
> return add3(x,y)++; //error: cannot assign to a function result
return add3(x, y) + 1;
Incidentally, ECMAScript does not have Scheme-like tail recursion, so
the examples from SICP will not all necessarily work.
More information about the Es-discuss