unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Daniel Llorens <daniel.llorens@bluewin.ch>
To: Daniel Hartwig <mandyke@gmail.com>
Cc: guile-user@gnu.org
Subject: Re: case-lambda* question
Date: Mon, 19 Nov 2012 10:43:51 +0100	[thread overview]
Message-ID: <D52D3714-B164-4D92-AEA4-7FF245395E7C@bluewin.ch> (raw)
In-Reply-To: <CAN3veRecoXn3CiLUT7_3tuwwSazkoXzu-pihcffh+kvxGNUugw@mail.gmail.com>


On Nov 15, 2012, at 02:22, Daniel Hartwig wrote:

> On 14 November 2012 18:20, Daniel Llorens <daniel.llorens@bluewin.ch> wrote:
>>> 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.
>> 
>> Do you mean something like this?
>> 
>> (define* (f a #:key x) x)
>> (define (g . args) (apply f args))
>> (g 0) -> #f
>> (g 0 #:x #t) -> #t
>> 
>> i.e. g must accept being called with 3 'arguments' so that it can forward the keyword args.
> 
> I was thinking of:
> 
> (define f
>  (case-lambda*
>   ((a . rest)
>    (if (memq #:x rest) …
> 
> where #:x is picked up from inside rest.
> 
> Based on the other error, I'd say that any case-lambda* with keyword
> arguments is matched with a rest argument instead, i.e. “a #:key x” is
> treated as “a . rest”.

Ok, I think I see how 

 (define f (case-lambda*
             ((x #:optional y) 1)
	     ((x #:key y)      2)
	     ((x y #:key z)    3)))

 (f #:y 2)

works. x is #:y and y is 2.

However, this should go to (x y #:key z) and it doesn't:

 (f 1 2 #:z 3) -> Odd length of keyword argument list

while given

(define g (case-lambda*
                       ((a #:key x) 1)
                       ((a b c #:key x) 3)))

this should match (a b c #:key x) and it doesn't. 

(g 1 2 3) - > Invalid keyword

Or maybe we should say that (g 1 2 3) shouldn't match (a #:key x)? Either way, I'll file these as a bug.

Thanks,

	Daniel




  reply	other threads:[~2012-11-19  9:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-12 13:54 case-lambda* question Daniel Llorens
2012-11-13  2:46 ` Daniel Hartwig
2012-11-14  0:55   ` Germán A. Arias
2012-11-14 10:20   ` Daniel Llorens
2012-11-14 17:53     ` Germán A. Arias
2012-11-15  1:01       ` Germán A. Arias
2013-01-14  9:41         ` Andy Wingo
2012-11-15  1:22     ` Daniel Hartwig
2012-11-19  9:43       ` Daniel Llorens [this message]
2013-01-14  9:39     ` Andy Wingo
2013-01-14 10:39 ` Andy Wingo
2013-01-14 12:22   ` Ludovic Courtès
2013-01-15 12:01   ` Daniel Llorens

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D52D3714-B164-4D92-AEA4-7FF245395E7C@bluewin.ch \
    --to=daniel.llorens@bluewin.ch \
    --cc=guile-user@gnu.org \
    --cc=mandyke@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).