Jason Orendorff wrote:
> On Fri, Aug 15, 2008 at 12:22 AM, Michael Haufe <[EMAIL PROTECTED]> 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
>> into JavaScript to see how it compared to Scheme and came across a
>> 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.
>
> -j
>
>
>
@Brendan:
Thanks for the corrections and the reference to rvalues and lvalues, it
sheds light on quite a few things since I was able to find quite a bit
of documentation on the terms.
@Jason:
Its from the 2nd SICP video (1b) at 14 minutes:
--------------------------------------------------------------
(define (+ x y)
(if (= x 0)
y
(+ (-1+ x) (1+ y))))
function add(x,y) (!x) ? y : add(--x,++y);
--------------------------------------------------------------
I don't claim to be a Scheme expert, but I believe my interpretation to be
correct.
I am also aware of the recursion limits of ES having used it for a number of
years.
This is for personal study and amusement.
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss