core: clean up split-lines with subseq-as. clean up subseq/subseq-as/subseq-unsafe/subseq-unsafe-as.
parent
1bc99066a7
commit
51b70b2050
|
@ -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*
|
||||
|
|
|
@ -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 ;
|
||||
|
||||
|
|
|
@ -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 ;
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue