]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences: change prepend to return type of first sequence to match append.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 29 May 2012 18:59:03 +0000 (11:59 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 29 May 2012 18:59:03 +0000 (11:59 -0700)
core/sequences/sequences-docs.factor
core/sequences/sequences-tests.factor
core/sequences/sequences.factor

index f3dfebedf722284e5f55d02ffcfb97bc60b91be5..9e3c197a9d51542a6b7400c2f916cad47cd4d49c 100644 (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." }
index 86624c0c19a0d0a1cd78b1eb1b4d12950b5c32af..9d560facbd0480968797af2438b5750eba2f74ae 100644 (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
index 0f208e2cabdcf882ae342b8c43b509063041eb32..33f2924769b2851f7e5fef17bbb9e7a377cd4da2 100644 (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 ;