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
Really, really basic question (negative numbers)
-
- Posts: 406
- Joined: Sat Mar 07, 2009 6:17 pm
- Location: Brazil
- Contact:
Re: Really, really basic question (negative numbers)
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)
Ah. I told you it was a basic question.
Many thanks. Works like a charm.
Kevin
Many thanks. Works like a charm.
Kevin