This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Really, really basic question (negative numbers)

3 posts · 5027 views

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)

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