From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Israelsson Tampe Newsgroups: gmane.lisp.guile.devel Subject: Re: new match system bug? Date: Sat, 4 Sep 2010 17:02:03 +0200 Message-ID: <201009041702.03513.stefan.tampe@spray.se> References: <201009041438.37352.stefan.tampe@spray.se> <878w3hy8xq.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_r9lgMui430+k+fS" X-Trace: dough.gmane.org 1283612549 31404 80.91.229.12 (4 Sep 2010 15:02:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 4 Sep 2010 15:02:29 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Sep 04 17:02:28 2010 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OruG7-0008Rt-UT for guile-devel@m.gmane.org; Sat, 04 Sep 2010 17:02:27 +0200 Original-Received: from localhost ([127.0.0.1]:58782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OruFy-0005LY-5m for guile-devel@m.gmane.org; Sat, 04 Sep 2010 11:02:14 -0400 Original-Received: from [140.186.70.92] (port=34209 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OruFp-0005KK-Mg for guile-devel@gnu.org; Sat, 04 Sep 2010 11:02:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OruFo-0006si-KD for guile-devel@gnu.org; Sat, 04 Sep 2010 11:02:05 -0400 Original-Received: from spsmtp02oc.mail2world.com ([74.202.142.198]:1081) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OruFo-0006sc-F5 for guile-devel@gnu.org; Sat, 04 Sep 2010 11:02:04 -0400 Original-Received: from mail pickup service by spsmtp02oc.mail2world.com with Microsoft SMTPSVC; Sat, 4 Sep 2010 08:02:03 -0700 auth-sender: stefan.tampe@spray.se Original-Received: from 82.182.254.46 unverified ([82.182.254.46]) by spsmtp02oc.mail2world.com with Mail2World SMTP Server; Sat, 04 Sep 2010 08:02:02 -0700 User-Agent: KMail/1.13.5 (Linux/2.6.34-12-desktop; KDE/4.4.4; x86_64; ; ) In-Reply-To: <878w3hy8xq.fsf@gnu.org> X-OriginalArrivalTime: 04 Sep 2010 15:02:03.0613 (UTC) FILETIME=[223C70D0:01CB4C42] X-detected-operating-system: by eggs.gnu.org: Windows 2000 SP4, XP SP1+ X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:10856 Archived-At: --Boundary-00=_r9lgMui430+k+fS Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Saturday, September 04, 2010 02:44:49 pm Ludovic Court=C3=A8s wrote: > Hello! >=20 > Stefan Israelsson Tampe writes: > > While eating the dogfood of the new match macro I come across a bug > > e.g, this does not work! > >=20 > > (match '(a b) ((and x (a ... b)) a)) >=20 > But: >=20 > scheme@(guile-user)> (match '(a b) ((and x (a . b)) a)) > $1 =3D a >=20 > According to the grammar in the manual, I don=E2=80=99t think literal =E2= =80=98...=E2=80=99 can > be used in the middle of a list; it should only be used at the end of a > list, where it means =E2=80=9Czero or more=E2=80=9D: >=20 > scheme@(guile-user)> (match '(a b) ((a ...) a)) > $2 =3D (a b) >=20 > Thanks, > Ludo=E2=80=99. I Included a trailing pattern error message to match.scm in this patch. /Stefan --Boundary-00=_r9lgMui430+k+fS Content-Type: text/x-patch; charset="UTF-8"; name="match-trailing.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="match-trailing.patch" diff --git a/module/ice-9/match.scm b/module/ice-9/match.scm index 1a2a61e..3a709a1 100644 --- a/module/ice-9/match.scm +++ b/module/ice-9/match.scm @@ -115,6 +115,36 @@ ((_ newpat m () v kt ke i) (syntax (match-one v newpat () kt ke i)))))) +;;error messag added +(define-syntax match-gen-ellipses + (syntax-rules () + ((_ v p () g+s (sk ...) fk i ((id id-ls) ...)) + (match-check-identifier p + ;; simplest case equivalent to (p ...), just bind the list + (let ((p v)) + (if (list? p) + (sk ... i) + fk)) + ;; simple case, match all elements of the list + (let loop ((ls v) (id-ls '()) ...) + (cond + ((null? ls) + (let ((id (reverse id-ls)) ...) (sk ... i))) + ((pair? ls) + (let ((w (car ls))) + (match-one w p ((car ls) (set-car! ls)) + (match-drop-ids (loop (cdr ls) (cons id id-ls) ...)) + fk i))) + (else + fk))))) + ((_ v p r g+s (sk ...) fk i ((id id-ls) ...)) + ;; general case, trailing patterns to match, keep track of the + ;; remaining list length so we don't need any backtracking + (match-verify-no-ellipses + r + (match-syntax-error + "trailing pattern to ... , eg. (x ... y) is not supported"))))) + ;;We must be able to extract vars in the new constructs!! (define-syntax match-extract-vars (syntax-rules (_ ___ *** ? $ = quote quasiquote and or not get! set!) @@ -241,5 +271,5 @@ #'(begin exp ...)))))) (include-from-path/filtered - (match-extract-vars match-two match) - "ice-9/match.upstream.scm") \ No newline at end of file + (match-gen-ellipses match-extract-vars match-two match) + "ice-9/match.upstream.scm") --Boundary-00=_r9lgMui430+k+fS--