guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: case-lambda* question


From: Daniel Hartwig
Subject: Re: case-lambda* question
Date: Tue, 13 Nov 2012 10:46:49 +0800

On 12 November 2012 21:54, Daniel Llorens <address@hidden> wrote:
>
> (define f
>         (case-lambda*
>                 ((a b c #:key x) 3)
>                 ((a #:key x) 1)))
>
> scheme@(guile-user)> (g 0 #:x 1)
> $1 = 3

Because ā€œ0 #:x 1ā€ is a valid match for ā€œa b cā€, you should rearrange
the case-lambda clauses.

When the doc. states keyword arguments do not contribute to the
success of a match, it refers only to keyword arguments in the
case-lambda clause, not at the call site.  This makes sense, otherwise
it would inhibit writing functions that detect keywords internally
from their rest arguments.

scheme@(guile-user)> (define g
                       (case-lambda*
                        ((a #:key x) 1)
                        ((a b c #:key x) 3)))
scheme@(guile-user)> (g 0 #:x 1)
$2 = 1

However, trying to call with three arguments then triggers an error,
and I am not sure why:

scheme@(guile-user)> (g 1 2 3)
<unnamed port>:46:1: In procedure g:
<unnamed port>:46:1: In procedure #<procedure g (a #:key x) | (a b c
#:key x)>: Invalid keyword

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> ,bt
In current input:
     46:1  0 (g 1 #<undefined> 2 3)

Definitely you need to rearrange the clauses.  About this error, I don't know!

Regards



reply via email to

[Prev in Thread] Current Thread [Next in Thread]