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" } "." }
|
{ $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." } ;
|
{ $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
|
HELP: clone-like
|
||||||
{ $values { "seq" sequence } { "exemplar" sequence } { "newseq" "a new sequence" } }
|
{ $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" } "." }
|
{ $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:"
|
"Extracting a subsequence:"
|
||||||
{ $subsections
|
{ $subsections
|
||||||
subseq
|
subseq
|
||||||
|
subseq-as
|
||||||
head
|
head
|
||||||
tail
|
tail
|
||||||
head*
|
head*
|
||||||
|
|
|
@ -313,13 +313,19 @@ C: <copy> copy-state
|
||||||
: copy-unsafe ( src i dst -- )
|
: copy-unsafe ( src i dst -- )
|
||||||
[ [ length check-length 0 ] keep ] 2dip <copy> (copy) drop ; inline
|
[ [ 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-unsafe ( from to seq -- subseq )
|
||||||
[ subseq>copy (copy) ] keep like ;
|
dup subseq-unsafe-as ; inline
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
: subseq-as ( from to seq exemplar -- subseq )
|
||||||
|
[ check-slice ] dip subseq-unsafe-as ;
|
||||||
|
|
||||||
: subseq ( from to seq -- subseq )
|
: subseq ( from to seq -- subseq )
|
||||||
[ check-slice subseq>copy (copy) ] keep like ;
|
dup subseq-as ; inline
|
||||||
|
|
||||||
: head ( seq n -- headseq ) (head) subseq ;
|
: head ( seq n -- headseq ) (head) subseq ;
|
||||||
|
|
||||||
|
|
|
@ -106,16 +106,12 @@ PRIVATE>
|
||||||
[ pick subseq ] keep swap
|
[ pick subseq ] keep swap
|
||||||
] map 2nip ;
|
] map 2nip ;
|
||||||
|
|
||||||
GENERIC: string-lines ( str -- seq )
|
: string-lines ( seq -- seq' )
|
||||||
|
|
||||||
M: string string-lines
|
|
||||||
[ V{ } clone 0 ] dip [ 2dup bounds-check? ] [
|
[ V{ } clone 0 ] dip [ 2dup bounds-check? ] [
|
||||||
2dup [ "\r\n" member? ] find-from swapd [
|
2dup [ "\r\n" member? ] find-from swapd [
|
||||||
over [ [ nip length ] keep ] unless
|
over [ [ nip length ] keep ] unless
|
||||||
[ subseq suffix! ] 2keep [ 1 + ] dip
|
[ "" subseq-as suffix! ] 2keep [ 1 + ] dip
|
||||||
] dip CHAR: \r eq? [
|
] dip CHAR: \r eq? [
|
||||||
2dup ?nth CHAR: \n eq? [ [ 1 + ] dip ] when
|
2dup ?nth CHAR: \n eq? [ [ 1 + ] dip ] when
|
||||||
] when
|
] when
|
||||||
] while 2drop { } like ;
|
] while 2drop { } like ;
|
||||||
|
|
||||||
M: sbuf string-lines "" like string-lines ;
|
|
||||||
|
|
|
@ -51,9 +51,6 @@ IN: sequences.extras
|
||||||
] each
|
] each
|
||||||
] each ; inline
|
] each ; inline
|
||||||
|
|
||||||
: subseq-as ( from to seq exemplar -- subseq )
|
|
||||||
[ check-slice subseq>copy (copy) ] dip like ;
|
|
||||||
|
|
||||||
: map-like ( seq exemplar -- seq' )
|
: map-like ( seq exemplar -- seq' )
|
||||||
'[ _ like ] map ; inline
|
'[ _ like ] map ; inline
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue