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: new match system bug? Date: Sat, 4 Sep 2010 14:38:37 +0200 Message-ID: <201009041438.37352.stefan.tampe@spray.se> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_N3jgMkUjtgSs8JK" X-Trace: dough.gmane.org 1283603929 3110 80.91.229.12 (4 Sep 2010 12:38:49 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 4 Sep 2010 12:38:49 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Sep 04 14:38:48 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 1Ors17-0007CR-Tg for guile-devel@m.gmane.org; Sat, 04 Sep 2010 14:38:46 +0200 Original-Received: from localhost ([127.0.0.1]:40161 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ors17-00070H-9O for guile-devel@m.gmane.org; Sat, 04 Sep 2010 08:38:45 -0400 Original-Received: from [140.186.70.92] (port=49514 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ors13-00070C-W5 for guile-devel@gnu.org; Sat, 04 Sep 2010 08:38:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Ors12-00020j-VY for guile-devel@gnu.org; Sat, 04 Sep 2010 08:38:41 -0400 Original-Received: from spsmtp02oc.mail2world.com ([74.202.142.198]:2808) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Ors12-00020M-QC for guile-devel@gnu.org; Sat, 04 Sep 2010 08:38:40 -0400 Original-Received: from mail pickup service by spsmtp02oc.mail2world.com with Microsoft SMTPSVC; Sat, 4 Sep 2010 05:38:38 -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 05:38:36 -0700 User-Agent: KMail/1.13.5 (Linux/2.6.34-12-desktop; KDE/4.4.4; x86_64; ; ) X-OriginalArrivalTime: 04 Sep 2010 12:38:38.0150 (UTC) FILETIME=[18FAFE60:01CB4C2E] 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:10852 Archived-At: --Boundary-00=_N3jgMkUjtgSs8JK Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi, While eating the dogfood of the new match macro I come across a bug e.g, this does not work! (match '(a b) ((and x (a ... b)) a)) But using the attached patch, it works!! Note. This should be interesting for upstreams maintainers. /Regards Stefan --Boundary-00=_N3jgMkUjtgSs8JK Content-Type: text/x-patch; charset="UTF-8"; name="match-gen-ellipses-bug.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="match-gen-ellipses-bug.patch" diff --git a/module/ice-9/match.scm b/module/ice-9/match.scm index 1a2a61e..b72d005 100644 --- a/module/ice-9/match.scm +++ b/module/ice-9/match.scm @@ -115,6 +115,53 @@ ((_ newpat m () v kt ke i) (syntax (match-one v newpat () kt ke i)))))) +;;Bug (match '(1 2) ((and x (a ... b)) b)) fails without the following fix +(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 + (let* ((tail-len (length 'r)) + (ls v) + (len (length ls))) + (if (< len tail-len) + fk + (let loop ((ls ls) (n len) (id-ls '()) ...) + (cond + ((= n tail-len) + (let ((id (reverse id-ls)) ...) + (match-one ls r (#f #f) (sk ...) fk i))) + ((pair? ls) + (let ((w (car ls))) + (match-one w p ((car ls) (set-car! ls)) + (match-drop-ids + (loop (cdr ls) (- n 1) (cons id id-ls) ...)) + fk + i))) + (else + fk))))))))) + ;;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 +288,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=_N3jgMkUjtgSs8JK--