From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Llorens Newsgroups: gmane.lisp.guile.user Subject: Re: case-lambda* question Date: Wed, 14 Nov 2012 11:20:21 +0100 Message-ID: <7A088671-9922-4ECF-A5C5-841AEFDBCA80@bluewin.ch> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Apple Message framework v1085) Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1352888437 1463 80.91.229.3 (14 Nov 2012 10:20:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 14 Nov 2012 10:20:37 +0000 (UTC) Cc: guile-user@gnu.org To: Daniel Hartwig , =?iso-8859-1?Q?=22Germ=E1n_A=2E_Arias=22?= Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Nov 14 11:20:47 2012 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TYa5O-0008MH-JF for guile-user@m.gmane.org; Wed, 14 Nov 2012 11:20:46 +0100 Original-Received: from localhost ([::1]:56953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYa5E-0005qB-OJ for guile-user@m.gmane.org; Wed, 14 Nov 2012 05:20:36 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:52261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYa58-0005pj-KZ for guile-user@gnu.org; Wed, 14 Nov 2012 05:20:33 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TYa55-0000er-IT for guile-user@gnu.org; Wed, 14 Nov 2012 05:20:30 -0500 Original-Received: from zhhdzmsp-smta18.bluewin.ch ([195.186.227.133]:33075) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYa55-0000eC-Bc for guile-user@gnu.org; Wed, 14 Nov 2012 05:20:27 -0500 Original-Received: from [195.186.99.130] ([195.186.99.130:37112] helo=zhbdzmsp-smta11.bluewin.ch) by zhhdzmsp-smta18.bluewin.ch (envelope-from ) (ecelerity 2.2.3.47 r(39824M)) with ESMTP id 51/7C-27475-76073A05; Wed, 14 Nov 2012 10:20:23 +0000 Original-Received: from [10.23.3.29] (128.179.67.121) by zhbdzmsp-smta11.bluewin.ch (8.5.142) (authenticated as dll@bluewin.ch) id 4F50AE9815CEC162; Wed, 14 Nov 2012 10:20:23 +0000 In-Reply-To: X-Mailer: Apple Mail (2.1085) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.186.227.133 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:9676 Archived-At: On Nov 13, 2012, at 03:46, Daniel Hartwig wrote: > On 12 November 2012 21:54, Daniel Llorens = wrote: >>=20 >> (define f >> (case-lambda* >> ((a b c #:key x) 3) >> ((a #:key x) 1))) >>=20 >> scheme@(guile-user)> (g 0 #:x 1) >> $1 =3D 3 >=20 > Because =930 #:x 1=94 is a valid match for =93a b c=94, you should = rearrange > the case-lambda clauses. >=20 > 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.=20 > 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 =3D 1 >=20 > However, trying to call with three arguments then triggers an error, > and I am not sure why: >=20 > scheme@(guile-user)> (g 1 2 3) > :46:1: In procedure g: > :46:1: In procedure # #:key x)>: Invalid keyword I saw this error too, but I thought it was the same logic as the other = case, where '1 2 3' =3D 3 arguments, so it matches 'a #:key x', just as = '0 #:x 1' matches 'a b c'. I think I see the difference now, but I still = find the manual unclear, it should at least give some examples of the = edge cases. On Nov 14, 2012, at 01:55, Germ=E1n A. Arias wrote: > This should be a bug. I tried with the example at test tree-il.test > (line 1073) but I get the same error. [...] Is this the test? (pass-if "case-lambda*" (null? (call-with-warnings (lambda () (compile '(let ((f (case-lambda* ((x #:optional y) 1) ((x #:key y) 2) ((x y #:key z) 3)))) (list (f 1) (f 1 2) (f #:y 2) (f 1 2 #:z 3))) #:opts %opts-w-arity #:to 'assembly))))) I also get an error here. Strangely, I can run make check without = anything being reported. I get a warning=20 UNRESOLVED: tree-il.test: warnings: unused-toplevel: used by macro But I still don't understand how case-lambda* works or should work. The = error is in the last call (f 1 2 #:z 3). If I remove it I get '(1 1 1), = but how can (f #:y 2) match (x #:optional y) ?? I'm running acc1d8=85 but this test has been in there since 2009 = apparently.