Page 1 of 1

Really, really basic question (negative numbers)

PostPosted: Tue Apr 28, 2009 10:11 pm
by keval
Greetings.
For what I'm sure is a really basic reason, I can't get negative numbers to work. I keep getting error messages about an undefined identifier. A simple example (finding the absolute value of an integer) that's copied directly out of SICP:

(define (ab x)
(cond ((< x 0) (-x))
(else x)))
> (ab 8)
8
> (ab -8)
. . reference to undefined identifier: -x

Can someone fill me in?
Thanks,
Kevin

Re: Really, really basic question (negative numbers)

PostPosted: Wed Apr 29, 2009 7:34 pm
by gugamilare
You need to put a space between - and x, or else the interpreter / compiler will think that -x is a symbol.

Re: Really, really basic question (negative numbers)

PostPosted: Wed Apr 29, 2009 9:01 pm
by keval
Ah. I told you it was a basic question.
Many thanks. Works like a charm.
Kevin