From 1320856d40e1b233bacbb730c93133bece693e92 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sun, 25 Sep 2011 15:52:39 +0900 Subject: [PATCH] fixing bug in (let ((x ...)) (match x (x ...))) --- lib/chibi/match/match.scm | 8 +++++--- tests/match-tests.scm | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/chibi/match/match.scm b/lib/chibi/match/match.scm index 6fc01a6f..97865566 100644 --- a/lib/chibi/match/match.scm +++ b/lib/chibi/match/match.scm @@ -1,5 +1,4 @@ -;;;; match.scm -- portable hygienic pattern matcher -;;;; -*- coding: utf-8 -*- +;;;; match.scm -- portable hygienic pattern matcher -*- coding: utf-8 -*- ;; ;; This code is written by Alex Shinn and placed in the ;; Public Domain. All warranties are disclaimed. @@ -211,6 +210,8 @@ ;; performance can be found at ;; http://synthcode.com/scheme/match-cond-expand.scm ;; +;; 2011/09/25 - fixing bug when directly matching an identifier repeated in +;; the pattern (thanks to Stefan Israelsson Tampe) ;; 2011/01/27 - fixing bug when matching tail patterns against improper lists ;; 2010/09/26 - adding `..1' patterns (thanks to Ludovic Courtès) ;; 2010/09/07 - fixing identifier extraction in some `...' and `***' patterns @@ -269,7 +270,8 @@ (let ((v #(vec ...))) (match-next v (v (set! v)) (pat . body) ...))) ((match atom (pat . body) ...) - (match-next atom (atom (set! atom)) (pat . body) ...)) + (let ((v atom)) + (match-next v (atom (set! atom)) (pat . body) ...))) )) ;; MATCH-NEXT passes each clause to MATCH-ONE in turn with its failure diff --git a/tests/match-tests.scm b/tests/match-tests.scm index 47bf44e7..e1e106e3 100644 --- a/tests/match-tests.scm +++ b/tests/match-tests.scm @@ -27,6 +27,7 @@ (test "duplicate symbols pass" 'ok (match '(ok . ok) ((x . x) x))) (test "duplicate symbols fail" 'ok (match '(ok . bad) ((x . x) 'bad) (else 'ok))) (test "duplicate symbols samth" 'ok (match '(ok . ok) ((x . 'bad) x) (('ok . x) x))) +(test "duplicate symbols bound" 3 (let ((a '(1 2))) (match a ((and (a 2) (1 b)) (+ a b)) (_ #f)))) (test "ellipses" '((a b c) (1 2 3)) (match '((a . 1) (b . 2) (c . 3))