Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Define atom in DrRacket?

681 views
Skip to first unread message

haziz

unread,
Dec 21, 2011, 8:38:57 AM12/21/11
to
I am trying to start the "Little Schemer" book and input the define atom definition from the preface into DrRacket (language selected R5RS):

(define atom?
(lambda (x)
(and (not pair? x)) (not (null? x))))

I was unable to get the confirmatory #f to (atom? (quote ())).

What am I doing wrong?

Thanks.

Jake Jarvis

unread,
Dec 21, 2011, 9:51:58 AM12/21/11
to
On 21.12.2011 14:38, wrote haziz:
> I am trying to start the "Little Schemer" book and input the define
> atom definition fromthe preface into DrRacket (language selected R5RS):
>
> (define atom?
> (lambda (x)
> (and (not pair? x)) (not (null? x))))
>
> I was unable to get the confirmatory #f to (atom? (quote ())).
>

What did you get instead? That is generally just as important as what
one didn't get.

> What am I doing wrong?
>

There are important parentheses missing, either already in the original,
or they got lost when transcribing.

The 'not' procedure takes 1 argument, you are giving it 2.

--
Jake Jarvis

Raffael Cavallaro

unread,
Dec 21, 2011, 10:06:24 AM12/21/11
to
On 2011-12-21 13:38:57 +0000, haziz said:

> I am trying to start the "Little Schemer" book and input the define
> atom definition from the preface into DrRacket (language selected R5RS):
>
> (define atom?
> (lambda (x)
> (and (not pair? x)) (not (null? x))))
^^^^^^^^^^^^^^

(not (pair? x))

i.e., pair? is a procedure that takes one argument so it must be called as:
(pair? arg)

You left out the left paren before 'pair?'
Notice how it doesn't look the same as the call:
(not (null? x))
which is correct.

warmest regards,

Ralph



>
> I was unable to get the confirmatory #f to (atom? (quote ())).
>
> What am I doing wrong?


--
Raffael Cavallaro

haziz

unread,
Dec 21, 2011, 12:48:08 PM12/21/11
to
Not sure it was the syntax. Solved it by adding #Lang Scheme at the top. I did not cut and paste my original commands above, so the typo may have arisen in this posting but not in DrRacket.

It would be helpful however to know what is the difference between R5RS, Scheme and Lazy Racket and Swindle?

Thanks.

Grant Rettke

unread,
Dec 21, 2011, 4:19:45 PM12/21/11
to
On Dec 21, 11:48 am, haziz <hsa...@gmail.com> wrote:
> Not sure it was the syntax. Solved it by adding #Lang Scheme at the top. I did not cut and paste my original commands
> above, so the typo may have arisen in this posting but not in DrRacket.

In DrRacket do alt shift ( to get matching brackets.

In Emacs, install Paredit.

Fyndhorn Elder

unread,
Jan 27, 2012, 6:20:55 AM1/27/12
to
Try this:

(define (coolnes? x)
(not (or (null? x)(pair? x))))

It's faster.

FE
0 new messages