Really, really basic question (negative numbers)

Discussion of Scheme and Racket
Post Reply
keval
Posts: 6
Joined: Tue Apr 28, 2009 10:06 pm

Really, really basic question (negative numbers)

Post by keval » Tue Apr 28, 2009 10:11 pm

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

gugamilare
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil
Contact:

Re: Really, really basic question (negative numbers)

Post by gugamilare » Wed Apr 29, 2009 7:34 pm

You need to put a space between - and x, or else the interpreter / compiler will think that -x is a symbol.

keval
Posts: 6
Joined: Tue Apr 28, 2009 10:06 pm

Re: Really, really basic question (negative numbers)

Post by keval » Wed Apr 29, 2009 9:01 pm

Ah. I told you it was a basic question.
Many thanks. Works like a charm.
Kevin

Post Reply