X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=blobdiff_plain;f=core%2Fsequences%2Fsequences-docs.factor;h=e46441de9512f14512ec54df3155739c0c8660d4;hp=6858135aa33edb0024d7859ebd4a0a55f39dbc08;hb=714c6d2b9464e193e24cb45fab1961d96a9d422c;hpb=2b73f2c90d9a2cc3e2b09dfd12ddb9b3a6d8e67d diff --git a/core/sequences/sequences-docs.factor b/core/sequences/sequences-docs.factor index 6858135aa3..e46441de95 100644 --- a/core/sequences/sequences-docs.factor +++ b/core/sequences/sequences-docs.factor @@ -846,6 +846,20 @@ HELP: slice-error } } ; +HELP: >slice< +{ $values + { "slice" slice } + { "from" integer } { "to" integer } { "seq" sequence } +} +{ $description "Sets up the stack for iteration with slots from a " { $link slice } ". Used with iteration in words such as " { $link sequence-operator } "." } ; + +HELP: >underlying< +{ $values + { "slice/seq" object } + { "i" integer } { "n" integer } +} +{ $description "Sets up the stack for iteration with slots from a " { $link sequence } ". Used with iteration in words such as " { $link sequence-operator } "." } ; + HELP: slice { $class-description "A virtual sequence which presents a subrange of the elements of an underlying sequence. New instances can be created by calling " { $link } ". Convenience words are also provided for creating slices where one endpoint is the start or end of the sequence; see " { $link "sequences-slices" } " for a list." $nl @@ -1070,6 +1084,13 @@ HELP: tail-slice* { tail-slice tail-slice* } related-words +HELP: head-to-index +{ $values + { "seq" sequence } { "to" integer } + { "zero" object } +} +{ $description "Sets up the stack for the " { $link head } " word." } ; + HELP: head { $values { "seq" sequence } { "n" "a non-negative integer" } { "headseq" "a new sequence" } } { $description "Outputs a new sequence consisting of the first " { $snippet "n" } " elements of the input sequence." } @@ -1086,6 +1107,13 @@ HELP: head } { $errors "Throws an error if the index is out of bounds." } ; +HELP: index-to-tail +{ $values + { "seq" sequence } { "from" integer } + { "length" object } +} +{ $description "Sets up the stack for the " { $link tail } " word." } ; + HELP: tail { $values { "seq" sequence } { "n" "a non-negative integer" } { "tailseq" "a new sequence" } } { $description "Outputs a new sequence consisting of the input sequence with the first " { $snippet "n" } " items removed." } @@ -1202,6 +1230,13 @@ HELP: subseq-index-from { $values { "n" "a start index" } { "seq" sequence } { "subseq" sequence } { "i/f" "a start index or " { $snippet "f" } } } { $description "Outputs the start index of the first contiguous subsequence equal to " { $snippet "subseq" } ", starting the search from the " { $snippet "n" } "th element. If no matching subsequence is found, outputs " { $link f } "." } ; +HELP: subseq-start-from +{ $values + { "subseq" object } { "seq" sequence } { "n" integer } + { "i/f" { $maybe integer } } +} +{ $description "Outputs the start index of the first contiguous subsequence equal to " { $snippet "subseq" } ", or " { $link f } " if no matching subsequence is found starting from " { $snippet "n" } "." } ; + HELP: subseq-start { $values { "subseq" sequence } { "seq" sequence } { "i/f" "a start index or " { $snippet "f" } } } { $description "Outputs the start index of the first contiguous subsequence equal to " { $snippet "subseq" } ", or " { $link f } " if no matching subsequence is found." } ; @@ -1210,7 +1245,7 @@ HELP: subseq? { $values { "subseq" sequence } { "seq" sequence } { "?" boolean } } { $description "Tests if " { $snippet "seq" } " contains the elements of " { $snippet "subseq" } " as a contiguous subsequence." } ; -HELP: subseq-index? +HELP: subseq-of? { $values { "seq" sequence } { "subseq" sequence } { "?" boolean } } { $description "Tests if " { $snippet "seq" } " contains the elements of " { $snippet "subseq" } " as a contiguous subsequence." } ; @@ -1252,14 +1287,68 @@ HELP: product HELP: infimum { $values { "seq" sequence } { "elt" object } } { $description "Outputs the least element of " { $snippet "seq" } "." } +{ $examples + "Example:" + { $example "USING: sequences prettyprint ;" + "{ 1 2 3 4 5 } infimum ." + "1" + } + "Example:" + { $example "USING: sequences prettyprint ;" + "{ \"c\" \"b\" \"a\" } infimum ." + "\"a\"" + } +} +{ $errors "Throws an error if the sequence is empty." } ; + +HELP: infimum-by +{ $values + { "seq" sequence } { "quot" quotation } + { "elt" object } +} +{ $description "Outputs the least element of " { $snippet "seq" } " according to the " { $snippet "quot" } "." } +{ $examples + "Example:" + { $example "USING: sequences prettyprint ;" + "{ { 1 2 } { 1 2 3 } { 1 2 3 4 } } [ length ] infimum-by ." + "{ 1 2 }" + } +} { $errors "Throws an error if the sequence is empty." } ; HELP: supremum { $values { "seq" sequence } { "elt" object } } { $description "Outputs the greatest element of " { $snippet "seq" } "." } +{ $examples + "Example:" + { $example "USING: sequences prettyprint ;" + "{ 1 2 3 4 5 } supremum ." + "5" + } + "Example:" + { $example "USING: sequences prettyprint ;" + "{ \"c\" \"b\" \"a\" } supremum ." + "\"c\"" + } +} +{ $errors "Throws an error if the sequence is empty." } ; + +HELP: supremum-by +{ $values + { "seq" sequence } { "quot" quotation } + { "elt" object } +} +{ $description "Outputs the greatest element of " { $snippet "seq" } " according to the " { $snippet "quot" } "." } +{ $examples + "Example:" + { $example "USING: sequences prettyprint ;" + "{ { 1 2 } { 1 2 3 } { 1 2 3 4 } } [ length ] supremum-by ." + "{ 1 2 3 4 }" + } +} { $errors "Throws an error if the sequence is empty." } ; -{ min max supremum infimum } related-words +{ min max infimum infimum-by supremum supremum-by } related-words HELP: shortest { $values { "seqs" sequence } { "elt" object } } @@ -1938,7 +2027,7 @@ ARTICLE: "sequences-tests" "Testing sequences" "Testing if a sequence contains an object:" { $subsections member? member-eq? } "Testing if a sequence contains a subsequence:" -{ $subsections head? tail? subseq? subseq-index? } ; +{ $subsections head? tail? subseq? subseq-of? } ; ARTICLE: "sequences-search" "Searching sequences" "Finding the index of an element:" @@ -1951,6 +2040,7 @@ ARTICLE: "sequences-search" "Searching sequences" "Finding the start of a subsequence:" { $subsections subseq-start + subseq-start-from subseq-index subseq-index-from subseq-starts-at?