]> gitweb.factorcode.org Git - factor.git/commitdiff
core: clean up split-lines with subseq-as. clean up subseq/subseq-as/subseq-unsafe...
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 5 Apr 2016 19:21:52 +0000 (12:21 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 5 Apr 2016 19:42:38 +0000 (12:42 -0700)
core/sequences/sequences-docs.factor
core/sequences/sequences.factor
core/splitting/splitting.factor
extra/sequences/extras/extras.factor

index 6b4a8907d49e38bf3633b5c05407b403dbc7459a..4eb46b2c657502444585d4e73ec8dfce7bedd10d 100644 (file)
@@ -990,6 +990,11 @@ HELP: subseq
 { $description "Outputs a new sequence consisting of all elements starting from and including " { $snippet "from" } ", and up to but not including " { $snippet "to" } "." }
 { $errors "Throws an error if " { $snippet "from" } " or " { $snippet "to" } " is out of bounds." } ;
 
+HELP: subseq-as
+{ $values { "from" "a non-negative integer" } { "to" "a non-negative integer" } { "seq" sequence } { "exemplar" sequence } { "subseq" "a new sequence" } }
+{ $description "Outputs a new sequence consisting of all elements starting from and including " { $snippet "from" } ", and up to but not including " { $snippet "to" } " of type " { $snippet "exemplar" } "." }
+{ $errors "Throws an error if " { $snippet "from" } " or " { $snippet "to" } " is out of bounds." } ;
+
 HELP: clone-like
 { $values { "seq" sequence } { "exemplar" sequence } { "newseq" "a new sequence" } }
 { $description "Outputs a newly-allocated sequence with the same elements as " { $snippet "seq" } " but of the same type as " { $snippet "exemplar" } "." }
@@ -1737,6 +1742,7 @@ $nl
 "Extracting a subsequence:"
 { $subsections
     subseq
+    subseq-as
     head
     tail
     head*
index c7b33ab846d914eb3dff7eebcc2ef72c33ba26d9..ddb0982fbab13fd393ee68725f9d11476ac7f21e 100644 (file)
@@ -313,13 +313,19 @@ C: <copy> copy-state
 : copy-unsafe ( src i dst -- )
     [ [ length check-length 0 ] keep ] 2dip <copy> (copy) drop ; inline
 
+: subseq-unsafe-as ( from to seq exemplar -- subseq )
+    [ subseq>copy (copy) ] dip like ;
+
 : subseq-unsafe ( from to seq -- subseq )
-    [ subseq>copy (copy) ] keep like ;
+    dup subseq-unsafe-as ; inline
 
 PRIVATE>
 
+: subseq-as ( from to seq exemplar -- subseq )
+    [ check-slice ] dip subseq-unsafe-as ;
+
 : subseq ( from to seq -- subseq )
-    [ check-slice subseq>copy (copy) ] keep like ;
+    dup subseq-as ; inline
 
 : head ( seq n -- headseq ) (head) subseq ;
 
index fc52580498784cc8eaef2dfab185294067dfea12..ac75d387b7fed4d29d99880bcf03916cfa8a5dd7 100644 (file)
@@ -106,16 +106,12 @@ PRIVATE>
         [ pick subseq ] keep swap
     ] map 2nip ;
 
-GENERIC: string-lines ( str -- seq )
-
-M: string string-lines
+: string-lines ( seq -- seq' )
     [ V{ } clone 0 ] dip [ 2dup bounds-check? ] [
         2dup [ "\r\n" member? ] find-from swapd [
             over [ [ nip length ] keep ] unless
-            [ subseq suffix! ] 2keep [ 1 + ] dip
+            [ "" subseq-as suffix! ] 2keep [ 1 + ] dip
         ] dip CHAR: \r eq? [
             2dup ?nth CHAR: \n eq? [ [ 1 + ] dip ] when
         ] when
-    ] while 2drop { } like ;
-
-M: sbuf string-lines "" like string-lines ;
+    ] while 2drop { } like ;
\ No newline at end of file
index 55f24785a1b37cd8aeb8ec7588c1e624d546e53c..1d9148dd2791f850b88bf21f68c8d4da1ab2d908 100644 (file)
@@ -51,9 +51,6 @@ IN: sequences.extras
         ] each
     ] each ; inline
 
-: subseq-as ( from to seq exemplar -- subseq )
-    [ check-slice subseq>copy (copy) ] dip like ;
-
 : map-like ( seq exemplar -- seq' )
     '[ _ like ] map ; inline