From 1369f6f5b22534f990522db0bede8d0df8bac4f1 Mon Sep 17 00:00:00 2001 From: "chris.double" Date: Mon, 27 Nov 2006 03:18:21 +0000 Subject: [PATCH] match: allow matching against empty sequences --- contrib/match/match.factor | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/match/match.factor b/contrib/match/match.factor index bcd7af1e70..ab0d739dea 100644 --- a/contrib/match/match.factor +++ b/contrib/match/match.factor @@ -24,6 +24,8 @@ USE: prettyprint drop f ] if ; +: && ( obj seq -- ? ) [ call ] all-with? ; + : (match) ( seq1 seq2 -- matched? ) { { [ 2dup = ] [ 2drop t ] } @@ -31,7 +33,7 @@ USE: prettyprint { [ dup _ = ] [ 2drop t ] } { [ dup match-var? ] [ set t ] } { [ over match-var? ] [ swap set t ] } - { [ over sequence? over sequence? and [ over first over first (match) ] [ f ] if ] [ >r 1 tail r> 1 tail (match) ] } + { [ over { [ sequence? ] [ empty? not ] } && over { [ sequence? ] [ empty? not ] } && and [ over first over first (match) ] [ f ] if ] [ >r 1 tail r> 1 tail (match) ] } { [ over tuple? over tuple? and ] [ >r tuple>array r> tuple>array (match) ] } { [ t ] [ 2drop f ] } } cond ;