sequences: change prepend to return type of first sequence to match append.

db4
John Benediktsson 2012-05-29 11:59:03 -07:00
parent 2db76ac23c
commit 1a6be98c45
3 changed files with 29 additions and 7 deletions

View File

@ -785,11 +785,11 @@ HELP: append-as
HELP: prepend
{ $values { "seq1" sequence } { "seq2" sequence } { "newseq" sequence } }
{ $description "Outputs a new sequence of the same type as " { $snippet "seq2" } " consisting of the elements of " { $snippet "seq2" } " followed by " { $snippet "seq1" } "." }
{ $errors "Throws an error if " { $snippet "seq1" } " contains elements not permitted in sequences of the same class as " { $snippet "seq2" } "." }
{ $description "Outputs a new sequence of the same type as " { $snippet "seq1" } " consisting of the elements of " { $snippet "seq2" } " followed by " { $snippet "seq1" } "." }
{ $errors "Throws an error if " { $snippet "seq2" } " contains elements not permitted in sequences of the same class as " { $snippet "seq1" } "." }
{ $examples { $example "USING: prettyprint sequences ;"
"{ 1 2 } B{ 3 4 } prepend ."
"B{ 3 4 1 2 }"
"{ 3 4 1 2 }"
}
{ $example "USING: prettyprint sequences strings ;"
"\"go\" \"car\" prepend ."
@ -797,6 +797,23 @@ HELP: prepend
}
} ;
HELP: prepend-as
{ $values { "seq1" sequence } { "seq2" sequence } { "exemplar" sequence } { "newseq" sequence } }
{ $description "Outputs a new sequence of the same type as " { $snippet "exemplar" } " consisting of the elements of " { $snippet "seq2" } " followed by " { $snippet "seq1" } "." }
{ $errors "Throws an error if " { $snippet "seq1" } " or " { $snippet "seq2" } " contain elements not permitted in sequences of the same class as " { $snippet "exemplar" } "." }
{ $examples
{ $example "USING: prettyprint sequences ;"
"{ 3 4 } B{ 1 2 } B{ } prepend-as ."
"B{ 1 2 3 4 }"
}
{ $example "USING: prettyprint sequences strings ;"
"\"ing\" \"go\" SBUF\" \" prepend-as ."
"SBUF\" going\""
}
} ;
{ prepend prepend-as } related-words
HELP: 3append
{ $values { "seq1" sequence } { "seq2" sequence } { "seq3" sequence } { "newseq" sequence } }
{ $description "Outputs a new sequence consisting of the elements of " { $snippet "seq1" } ", " { $snippet "seq2" } " and " { $snippet "seq3" } " in turn." }

View File

@ -1,6 +1,6 @@
USING: arrays kernel math math.order math.parser namespaces
sequences kernel.private sequences.private strings sbufs
tools.test vectors assocs generic vocabs.loader ;
USING: arrays byte-arrays kernel math math.order math.parser
namespaces sequences kernel.private sequences.private strings
sbufs tools.test vectors assocs generic vocabs.loader ;
IN: sequences.tests
[ "empty" ] [ { } [ "empty" ] [ "not empty" ] if-empty ] unit-test
@ -109,6 +109,9 @@ unit-test
[ "a" -1 append ] must-fail
[ -1 "a" append ] must-fail
{ t } [ B{ 0 } { 1 } append byte-array? ] unit-test
{ t } [ B{ 0 } { 1 } prepend byte-array? ] unit-test
[ [ ] ] [ 1 [ ] remove ] unit-test
[ [ ] ] [ 1 [ 1 ] remove ] unit-test
[ [ 3 1 1 ] ] [ 2 [ 3 2 1 2 1 ] remove ] unit-test

View File

@ -352,7 +352,9 @@ PRIVATE>
: append ( seq1 seq2 -- newseq ) over append-as ;
: prepend ( seq1 seq2 -- newseq ) swap append ; inline
: prepend-as ( seq1 seq2 exemplar -- newseq ) swapd append-as ; inline
: prepend ( seq1 seq2 -- newseq ) over prepend-as ; inline
: 3append ( seq1 seq2 seq3 -- newseq ) pick 3append-as ;