From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Newsgroups: gmane.lisp.guile.bugs Subject: bug#9776: case-lambda should accept zero clauses Date: Thu, 02 Feb 2012 23:16:45 +0100 Message-ID: <877h04swxe.fsf@gnu.org> References: <87ty77c4ab.fsf@weinholt.se> <87fwftu7lt.fsf@gnu.org> <87ehvals3q.fsf@Kagami.home> <87k447bhyc.fsf@gnu.org> <87hazbdtuo.fsf@netris.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1328221060 18526 80.91.229.3 (2 Feb 2012 22:17:40 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 2 Feb 2012 22:17:40 +0000 (UTC) Cc: 9776@debbugs.gnu.org, =?UTF-8?Q?G=C3=B6ran?= Weinholt , Ian Price To: Mark H Weaver Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Thu Feb 02 23:17:39 2012 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Rt4yI-00075T-NQ for guile-bugs@m.gmane.org; Thu, 02 Feb 2012 23:17:39 +0100 Original-Received: from localhost ([::1]:34376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rt4yI-0001OO-6F for guile-bugs@m.gmane.org; Thu, 02 Feb 2012 17:17:38 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:50072) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rt4yE-0001Mp-Q8 for bug-guile@gnu.org; Thu, 02 Feb 2012 17:17:35 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rt4yD-0005My-Fy for bug-guile@gnu.org; Thu, 02 Feb 2012 17:17:34 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:47762) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rt4yD-0005Mt-Be for bug-guile@gnu.org; Thu, 02 Feb 2012 17:17:33 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Rt4yg-0002hn-2q for bug-guile@gnu.org; Thu, 02 Feb 2012 17:18:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-guile@gnu.org Resent-Date: Thu, 02 Feb 2012 22:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 9776 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 9776-submit@debbugs.gnu.org id=B9776.132822103910334 (code B ref 9776); Thu, 02 Feb 2012 22:18:02 +0000 Original-Received: (at 9776) by debbugs.gnu.org; 2 Feb 2012 22:17:19 +0000 Original-Received: from localhost ([127.0.0.1]:51384 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Rt4xz-0002gd-Dj for submit@debbugs.gnu.org; Thu, 02 Feb 2012 17:17:19 -0500 Original-Received: from xanadu.aquilenet.fr ([88.191.123.111]:48978) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Rt4xx-0002gW-B7 for 9776@debbugs.gnu.org; Thu, 02 Feb 2012 17:17:18 -0500 Original-Received: from localhost (xanadu.aquilenet.fr [127.0.0.1]) by xanadu.aquilenet.fr (Postfix) with ESMTP id 5F5971770; Thu, 2 Feb 2012 23:16:47 +0100 (CET) Original-Received: from xanadu.aquilenet.fr ([127.0.0.1]) by localhost (xanadu.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yvFJm2FRmm9a; Thu, 2 Feb 2012 23:16:47 +0100 (CET) Original-Received: from pluto (reverse-83.fdn.fr [80.67.176.83]) by xanadu.aquilenet.fr (Postfix) with ESMTPSA id 0364EDC2; Thu, 2 Feb 2012 23:16:45 +0100 (CET) X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 14 =?UTF-8?Q?Pluvi=C3=B4se?= an 220 de la =?UTF-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu In-Reply-To: <87hazbdtuo.fsf@netris.org> (Mark H. Weaver's message of "Wed, 01 Feb 2012 00:07:43 -0500") User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.93 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:6170 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Mark, Mark H Weaver skribis: > Thanks for tackling this. Of course this is Andy's area, but psyntax is > still fresh in my mind, so I'll attempt a review as well as my own > tentative approach. Psyntax is not yet a place where I feel comfortable, so I appreciate. :-) > ludo@gnu.org (Ludovic Court=C3=A8s) writes: >> So, here=E2=80=99s a tentative patch for review: >> >> >> Modified module/ice-9/psyntax.scm >> diff --git a/module/ice-9/psyntax.scm b/module/ice-9/psyntax.scm >> index 728ab12..c3aa6d8 100644 >> --- a/module/ice-9/psyntax.scm >> +++ b/module/ice-9/psyntax.scm >> @@ -1778,7 +1778,19 @@ >> r* w* mod))))) >>=20=20 >> (syntax-case clauses () >> - (() (values '() #f)) >> + (() ; zero clauses >> + (values >> + '() >> + (build-lambda-case s '() '() 'rest #f '() >> + (list (build-lexical-var s 'rest)) >> + (build-application s >> + (make-toplevel-ref s = 'throw) > > This 'make-toplevel-ref' should instead be 'build-primref', so that it > refers to the 'throw' in the 'guile' module. As it is now, this won't > work in modules that have bound 'throw' to something else. Oh, OK. >> + (list >> + (build-data >> + s 'wrong-number-of-= args) >> + (build-data >> + s "Wrong number of = arguments"))) >> + #f))) > > Unfortunately, the above case is not only triggered for an empty > case-lambda; it is the base case at the end of iteration over the > clauses, so this code will be added to _every_ case-lambda. Oops, indeed. > Apart from the extra bloat, this will make error reporting much worse. > Right now, if you call a procedure created by 'case-lambda' with an > incorrect number of arguments, the VM will generate a nice error message > that includes the procedure itself, including the procedure's name. > > By adding this "catch-all" clause to the end of every 'case-lambda', you > have taken over the job of error reporting for _all_ case-lambdas, but > you produce a much less useful error message than the VM does. > > This also destroys the arity information for all case-lambdas. OK, I see. [...] > Here's how it reports errors: > >> scheme@(guile-user)> (define foo (case-lambda)) >> scheme@(guile-user)> (foo) >> ;;; :2:0: warning: possibly wrong number of arguments to `foo' >> ERROR: In procedure foo: >> ERROR: Wrong number of arguments to # [...] > + ;; a terrible hack to produce helpful error= messages in most cases > + #`(lambda (created by case-lambda with no c= lauses > + a b c d e f g h i j k l = m n o p q r s t u v w x y z) > + (scm-error > + '#,'wrong-number-of-args #f > + "Wrong number of arguments to a proced= ure created by case-lambda with no clauses" > + '() #f)) But this is terrrrrible! What about something along these lines instead (untested): --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/module/ice-9/psyntax.scm b/module/ice-9/psyntax.scm index 728ab12..da7f16a 100644 --- a/module/ice-9/psyntax.scm +++ b/module/ice-9/psyntax.scm @@ -1704,7 +1704,7 @@ orig-args)))) (req orig-args '()))) - (define expand-lambda-case + (define expand-lambda-case* (lambda (e r w s mod get-formals clauses) (define (parse-req req opt rest kw body) (let ((vars (map gen-var req)) @@ -1795,6 +1795,25 @@ (build-lambda-case s req opt rest kw inits vars body else*)))))))))))) + (define expand-lambda-case + (lambda (e r w s mod get-formals clauses) + (syntax-case clauses () + (() + (values + '() + (build-lambda-case s '() '() 'rest #f '() + (list (build-lexical-var s 'rest)) + (build-application s + (build-primref s 'throw) + (list + (build-data + s 'wrong-number-of-args) + (build-data + s "Wrong number of arguments"))) + #f))) + (((args e1 e2 ...) (args* e1* e2* ...) ...) + (expand-lambda-case* e r w s mod get-formal clauses))))) + ;; data ;; strips syntax-objects down to top-wrap --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable The idea would be to explicitly check for the zero-clause case before any recursive call is made. Thanks, Ludo=E2=80=99. --=-=-=--