1 USING: help.markup help.syntax kernel math sequences ;
8 { "quot" { $quotation ( ... elt1 elt2 -- ... ? ) } }
10 { $description "Efficiently counts how many pairwise elements of " { $snippet "seq1" } " and " { $snippet "seq2" } " that the predicate quotation matches." }
12 { $example "USING: kernel prettyprint sequences.extras ;" "{ 1 2 3 } { 3 2 1 } [ = ] 2count ." "1" } }
19 { "quot" { $quotation ( ... elt1 elt2 index -- ... ) } } }
20 { $description "Applies " { $snippet "quot" } " to each pair of elements from " { $snippet "seq1" } " and " { $snippet "seq2" } ", providing the index of the elements at the top of the stack." }
21 { $see-also 2each each-index } ;
27 { "quot" { $quotation ( ... elt1 elt2 -- ... newelt ) } } }
28 { $description "Applies the quotation to each pair of elements from " { $snippet "seq1" } " and " { $snippet "seq2" } ", yielding a new element, and storing it back into " { $snippet "seq1" } ". Returns " { $snippet "seq1" } "." }
29 { $see-also 2map map! } ;
35 { "quot" { $quotation ( ... elt1 elt2 index -- ... newelt ) } }
36 { "newseq" sequence } }
37 { $description "Calls the quotation with each pair of elements of the two sequences and their index on the stack, with the index on the top of the stack. Collects the outputs of the quotation and outputs them into a new sequence of the same type as the first sequence." }
38 { $see-also 2map map-index } ;
43 { "quot" { $quotation ( ... elt -- ... ? ) } }
45 { $description "Outputs the fraction of elements in the sequence for which the predicate quotation matches." }
46 { $examples { $example "USING: math math.ranges prettyprint sequences.extras ;" "100 [1,b] [ even? ] count* ." "1/2" } } ;
51 { "quot" { $quotation ( ... elt -- ... ? ) } }
54 { $description "Generate a new sequence where all runs of elements for which the predicate returns true are replaced by a single instance of " { $snippet "elt" } "." }
57 "Collapse multiple spaces in a string down to a single space"
58 { $example "USING: kernel prettyprint sequences.extras ;" "\" Hello, crazy world \" [ CHAR: \\s = ] \" \" collapse ." "\" Hello, crazy world \"" } } ;
63 { "quot" { $quotation ( ... elt -- ... ? ) } }
66 { $description "Generate a new sequence where all runs of elements for which the predicate returns true are replaced by a single instance of " { $snippet "elt" } ". Runs at the beginning or end of the sequence for which the predicate returns true are removed." }
67 { $see-also collapse }
69 "Collapse multiple spaces in a string down to a single space"
70 { $example "USING: kernel prettyprint sequences.extras ;" "\" Hello, crazy world \" [ CHAR: \\s = ] \" \" compact ." "\"Hello, crazy world\"" } } ;
73 { $values { "seq" sequence } { "evens" evens } }
74 { $description "Create a virtual sequence whose elements consist of the even-indexed elements from the original sequence." }
75 { $notes "Because sequences are zero-indexed, this collection includes the first, third, fifth, etc. elements of the actual sequence which can be counterintuitive." }
76 { $see-also <odds> } ;
81 { "quot" { $quotation ( ... elt -- ... ? ) } }
82 { "elts" "the indices of the matching elements" } }
83 { $description "Similar to " { $link find } ", but finds all of the indices and elements that match the provided quotation, not just the first." }
84 { $notes "The result is provided as an array of arrays, whose first value is the index and whose second value is the element." } ;
91 { $description "Checks whether the first element of " { $snippet "seq" } " is equal to " { $snippet "elt" } "." } ;
96 { "quot" { $quotation ( ... elt -- ... ? ) } }
98 { $description "Tests whether the first element of " { $snippet "seq" } " satisfies the provided predicate." } ;
105 { $description "Checks whether the fourth element of " { $snippet "seq" } " is equal to " { $snippet "elt" } "." } ;
110 { "quot" { $quotation ( ... elt -- ... ? ) } }
112 { $description "Tests whether the fourth element of " { $snippet "seq" } " satisfies the provided predicate." } ;
115 { $values { "seq" sequence } { "odds" odds } }
116 { $description "Create a virtual sequence whose elements consist of the odd-indexed elements from the original sequence." }
117 { $notes "Because sequences are zero-indexed, this collection includes the second, fourth, sixth, etc. elements of the actual sequence which can be counterintuitive." }
118 { $see-also <evens> } ;
121 { $values { "seq" sequence } { "accum" sequence } }
122 { $description "Converts a sequence into the nearest resizable equivalent, preserving its contents." } ;
129 { $description "Checks whether the second element of " { $snippet "seq" } " is equal to " { $snippet "elt" } "." } ;
134 { "quot" { $quotation ( ... elt -- ... ? ) } }
136 { $description "Tests whether the second element of " { $snippet "seq" } " satisfies the provided predicate." } ;
140 { "from" integer } { "to" integer } { "seq" sequence } { "subseq" sequence } }
141 { $description "Outputs a new sequence using positions relative to one or both ends of the sequence. Positive values describes offsets relative to the start of the sequence, negative values relative to the end. Values of " { $link f } " for " { $snippet "from" } " indicate the beginning of the sequence, while an " { $link f } " for " { $snippet "to" } " indicates the end of the sequence." }
142 { $notes "Both " { $snippet "from" } " and " { $snippet "to" } " can be safely set to values outside the length of the sequence. Also, " { $snippet "from" } " can safely reference a smaller or greater index position than " { $snippet "to" } "." }
144 "Using a negative relative index:"
145 { $example "USING: prettyprint sequences.extras ; 2 -1 \"abcdefg\" subseq* ."
148 "Using optional indices:"
149 { $example "USING: prettyprint sequences.extras ; f -4 \"abcdefg\" subseq* ."
152 "Using larger-than-necessary indices:"
153 { $example "USING: prettyprint sequences.extras ; 0 10 \"abcdefg\" subseq* ."
156 "Trimming from either end of the sequence."
157 { $example "USING: prettyprint sequences.extras ; 1 -1 \"abcdefg\" subseq* ."
167 { $description "Checks whether the third element of " { $snippet "seq" } " is equal to " { $snippet "elt" } "." } ;
172 { "quot" { $quotation ( ... elt -- ... ? ) } }
174 { $description "Tests whether the third element of " { $snippet "seq" } " satisfies the provided predicate." } ;
178 { "newseq" sequence }
181 { "seq1" sequence } }
182 { $description "Reverses the result of a " { $link surround } " call, stripping off the prefix " { $snippet "seq2" } " and suffix " { $snippet "seq3" } " to restore the original sequence " { $snippet "seq" } "." }
183 { $see-also surround } ;
187 { "subseq" sequence } { "seq" sequence } { "indices" sequence } }
188 { $description "Outputs the starting indices of the non-overlapping occurrences of " { $snippet "subseq" } " in " { $snippet "seq" } "." }
190 { $example "USING: prettyprint sequences.extras ; \"ABA\" \"ABABA\" start-all ."
193 { $example "USING: prettyprint sequences.extras ; \"ABA\" \"ABAABA\" start-all ."
200 { "subseq" sequence } { "seq" sequence } { "indices" sequence } }
201 { $description "Outputs the starting indices of the possibly overlapping occurrences of " { $snippet "subseq" } " in " { $snippet "seq" } "." }
203 { $example "USING: prettyprint sequences.extras ; \"ABA\" \"ABABA\" start-all* ."
209 { "subseq" sequence } { "seq" sequence } { "n" integer } }
210 { $description "Outputs the number of non-overlapping occurrences of " { $snippet "subseq" } " in " { $snippet "seq" } "." }
212 { $example "USING: prettyprint sequences.extras ; \"ABA\" \"ABABA\" count-subseq ."
219 { "subseq" sequence } { "seq" sequence } { "n" integer } }
220 { $description "Outputs the number of possibly overlapping occurrences of " { $snippet "subseq" } " in " { $snippet "seq" } "." }
222 { $example "USING: prettyprint sequences.extras ; \"ABA\" \"ABABA\" count-subseq* ."
226 { start-all start-all* count-subseq count-subseq* } related-words