[plt-scheme] lambda argument lists that contain only a rest argument
Ah... very cool. My thanks to Psy-Kosh, Eli, and Jon.
On 3/21/07, Jon Zeppieri <zeppieri at gmail.com> wrote:
> On 3/22/07, Ethan Herdrick <info at reatlas.com> wrote:
> > Why is this OK:
> > (define (rest-only . r)
> > r)
> >
> > But this can't even be read into the interpreter:
> > (define rest-only
> > (λ ( . r)
> > r))
> >
>
> The former is equivalent to:
>
> (define rest-only (λ r r))
>
> ...not:
>
> (define rest-only (λ ( . r) r))
>
> ...which, as you've noticed, is a syntax error.
>
>
> (λ x ...) is a procedure that takes any number of arguments.
> (λ (x . y) ...) is a procedure that takes at least one argument.
> (λ (x y . z) ...) is procedure that takes at least two arguments.
>
> (define (foo . x) ...) defines a procedure foo, which takes any number
> of arguments.
> (define (foo x . y) ...) defines a procedure foo, which takes at least
> one argument.
>
> ... and so forth.
>