match: cleanup

db4
Slava Pestov 2009-09-04 06:11:28 -05:00
parent 223b907219
commit c9e04cd8f5
1 changed files with 3 additions and 7 deletions

View File

@ -69,10 +69,9 @@ MACRO: match-cond ( assoc -- )
dup length zero? not [ rest ] [ drop f ] if ; dup length zero? not [ rest ] [ drop f ] if ;
: (match-first) ( seq pattern-seq -- bindings leftover/f ) : (match-first) ( seq pattern-seq -- bindings leftover/f )
2dup [ length ] bi@ < [ 2drop f f ] 2dup shorter? [ 2drop f f ] [
[
2dup length head over match 2dup length head over match
[ nip swap ?1-tail ] [ [ rest ] dip (match-first) ] if* [ swap ?1-tail ] [ [ rest ] dip (match-first) ] ?if
] if ; ] if ;
: match-first ( seq pattern-seq -- bindings ) : match-first ( seq pattern-seq -- bindings )
@ -80,10 +79,7 @@ MACRO: match-cond ( assoc -- )
: (match-all) ( seq pattern-seq -- ) : (match-all) ( seq pattern-seq -- )
[ nip ] [ (match-first) swap ] 2bi [ nip ] [ (match-first) swap ] 2bi
[ [ , [ swap (match-all) ] [ drop ] if* ] [ 2drop ] if* ;
, [ swap (match-all) ] [ drop ] if*
] [ 2drop ] if* ;
: match-all ( seq pattern-seq -- bindings-seq ) : match-all ( seq pattern-seq -- bindings-seq )
[ (match-all) ] { } make ; [ (match-all) ] { } make ;