[plt-scheme] dot notation issue

From: Grant Rettke (grettke at acm.org)
Date: Sat Feb 7 22:16:00 EST 2009

On Fri, Feb 6, 2009 at 5:46 PM, Lisa Gandy <redlmg98 at hotmail.com> wrote:
> I have the following code..
> (define (same-parity p . x)
>     (define ind (remainder p 2))
>     (cond ((null? x) '())
>           ((= ind (remainder (car x) 2))
>           (cons (car x) (same-parity p (cdr x))))
>           (else (same-parity p (cdr x)))))
> What is going on here?

The first time you apply the function, p is bound to the first
argument, and x is bound to a list of the rest of the arguments.

When you take the iterative step, p is bound to the first argument
which is a list of the rest of arguments from the previous steps.

That is why YC's fix would work. You should play around with the dot
define shape like Richard suggested to see what is happening.


Posted on the users mailing list.