]> gitweb.factorcode.org Git - factor.git/commitdiff
splitting: add split*-when-slice and change to not use make.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 27 Mar 2013 23:19:56 +0000 (16:19 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 27 Mar 2013 23:19:56 +0000 (16:19 -0700)
core/splitting/splitting.factor

index 39ca33bd409d473a2d5bc522cf6de52e0e5c0d7d..9a430c0dfd7991cd53a10d2f62b396d7cde326ec 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2005, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays kernel make math sequences strings sbufs ;
+USING: arrays kernel math sequences strings sbufs ;
 IN: splitting
 
 <PRIVATE
@@ -97,22 +97,25 @@ PRIVATE>
 
 <PRIVATE
 
-: (split*) ( n seq quot: ( ... elt -- ... ? ) -- )
-    [ find-from ]
-    [ [ [ 1 + ] 3dip [ 3dup swapd subseq , ] dip [ drop ] 2dip (split*) ] 3curry ]
-    [ drop [ [ drop ] 2dip 2dup length < [ swap [ tail ] unless-zero , ] [ 2drop ] if ] 2curry ]
-    3tri if ; inline recursive
-
-: split*, ( ... seq quot: ( ... elt -- ... ? ) -- ... )
-    [ 0 ] 2dip (split*) ; inline
+: (split*) ( n seq quot: ( ... elt -- ... ? ) quot -- )
+    pick [
+        swap curry [ 1 + ] prepose [ keep 1 + swap ] curry
+        [ [ find-from drop dup ] 2curry [ dup ] prepose ] dip
+        produce nip
+    ] keep rot over dupd length < [
+        [ tail ] unless-zero suffix
+    ] [ 2drop ] if ; inline
 
 PRIVATE>
 
-: split* ( seq separators -- pieces )
-    [ [ member? ] curry split*, ] { } make ; inline
-
 : split*-when ( ... seq quot: ( ... elt -- ... ? ) -- ... pieces )
-    [ split*, ] { } make ; inline
+    [ 0 ] 2dip [ subseq ] (split*) ; inline
+
+: split*-when-slice ( ... seq quot: ( ... elt -- ... ? ) -- ... pieces )
+    [ 0 ] 2dip [ <slice> ] (split*) ; inline
+
+: split* ( seq separators -- pieces )
+    [ member? ] curry split*-when ; inline
 
 GENERIC: string-lines ( str -- seq )