From d5bd3fa44d9b4eec029a10b900900040e3536075 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Thu, 27 Jan 2011 21:37:03 +0900 Subject: [PATCH] fixing bug when matching tail patterns against improper lists --- lib/chibi/match/match.scm | 7 ++++--- tests/match-tests.scm | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/chibi/match/match.scm b/lib/chibi/match/match.scm index ce2ed69c..dbb00167 100644 --- a/lib/chibi/match/match.scm +++ b/lib/chibi/match/match.scm @@ -28,7 +28,8 @@ ;; performance can be found at ;; http://synthcode.com/scheme/match-cond-expand.scm ;; -;; 2010/09/26 - adding `..1' patterns (thanks to Ludovic Courts) +;; 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 ;; 2009/11/25 - adding `***' tree search patterns ;; 2008/03/20 - fixing bug where (a ...) matched non-lists @@ -320,8 +321,8 @@ r (let* ((tail-len (length 'r)) (ls v) - (len (length ls))) - (if (< len tail-len) + (len (and (list? ls) (length ls)))) + (if (or (not len) (< len tail-len)) fk (let loop ((ls ls) (n len) (id-ls '()) ...) (cond diff --git a/tests/match-tests.scm b/tests/match-tests.scm index 0d571963..1998276b 100644 --- a/tests/match-tests.scm +++ b/tests/match-tests.scm @@ -1,5 +1,5 @@ -(import (chibi match) (chibi test)) +;;(import (chibi match) (chibi test)) (test-begin "match") @@ -90,6 +90,11 @@ (match '((a . 1) (b . 2) (c . 3) (d . 4) (e . 5)) (((x . y) ... u v w) (list x y u v w)))) +(test "tail against improper list" #f + (match '(a b c d e f . g) + ((x ... y u v w) (list x y u v w)) + (else #f))) + (test "Riastradh quasiquote" '(2 3) (match '(1 2 3) (`(1 ,b ,c) (list b c))))