]> gitweb.factorcode.org Git - factor.git/blob - core/splitting/splitting-docs.factor
core: use $sequence help-markup in a few places.
[factor.git] / core / splitting / splitting-docs.factor
1 USING: help.markup help.syntax kernel sequences strings ;
2 IN: splitting
3
4 ARTICLE: "sequences-split" "Splitting sequences"
5 "Splitting sequences at occurrences of subsequences:"
6 { $subsections
7     ?head
8     ?head-slice
9     ?tail
10     ?tail-slice
11     split1
12     split1-slice
13     split1-when
14     split1-when-slice
15     split1-last
16     split1-last-slice
17     split
18     split-when
19     split-when-slice
20 }
21 "Splitting a string into lines:"
22 { $subsections string-lines }
23 "Replacing subsequences with another subsequence:"
24 { $subsections replace } ;
25
26 ABOUT: "sequences-split"
27
28 HELP: split1
29 { $values { "seq" sequence } { "subseq" sequence } { "before" "a new sequence" } { "after" "a new sequence" } }
30 { $description "Splits " { $snippet "seq" } " at the first occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
31
32 HELP: split1-slice
33 { $values { "seq" sequence } { "subseq" sequence } { "before-slice" slice } { "after-slice" slice } }
34 { $description "Splits " { $snippet "seq" } " at the first occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split as slices. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
35
36 HELP: split1-when
37 { $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... ? ) } } { "before" "a new sequence" } { "after" "a new sequence" } }
38 { $description "Splits " { $snippet "seq" } " at the first occurrence of an element for which " { $snippet "quot" } " gives a true output and outputs the pieces before and after the split." } ;
39
40 HELP: split1-when-slice
41 { $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... ? ) } } { "before-slice" slice } { "after-slice" slice } }
42 { $description "Splits " { $snippet "seq" } " at the first occurrence of an element for which " { $snippet "quot" } " gives a true output and outputs the pieces before and after the split as slices. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
43
44 HELP: split1-last
45 { $values { "seq" sequence } { "subseq" sequence } { "before" "a new sequence" } { "after" "a new sequence" } }
46 { $description "Splits " { $snippet "seq" } " at the last occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
47
48 HELP: split1-last-slice
49 { $values { "seq" sequence } { "subseq" sequence } { "before-slice" slice } { "after-slice" slice } }
50 { $description "Splits " { $snippet "seq" } " at the last occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split as slices. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
51
52 { split1 split1-slice split1-last split1-last-slice } related-words
53
54 HELP: split-when
55 { $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... ? ) } } { "pieces" "a new array" } }
56 { $description "Splits " { $snippet "seq" } " at each occurrence of an element for which " { $snippet "quot" } " gives a true output and outputs an array of pieces. The pieces do not include the elements along which the sequence was split." }
57 { $examples { $example "USING: ascii kernel prettyprint splitting ;" "\"hello,world-how.are:you\" [ letter? not ] split-when ." "{ \"hello\" \"world\" \"how\" \"are\" \"you\" }" } } ;
58
59 HELP: split-when-slice
60 { $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... ? ) } } { "pieces" "a new array" } }
61 { $description "Splits " { $snippet "seq" } " at each occurrence of an element for which " { $snippet "quot" } " gives a true output and outputs an array of pieces as slices. The pieces do not include the elements along which the sequence was split." } ;
62
63 HELP: split-indices
64 { $values { "seq" sequence } { "indices" sequence } { "pieces" "a new array" } }
65 { $description "Splits a sequence at the given indices." }
66 { $examples
67   { $example
68     "USING: prettyprint splitting ;"
69     "\"hello world\" { 3 6 } split-indices ."
70     "{ \"hel\" \"lo \" \"world\" }"
71   }
72 } ;
73
74 HELP: split
75 { $values { "seq" sequence } { "separators" sequence } { "pieces" "a new array" } }
76 { $description "Splits " { $snippet "seq" } " at each occurrence of an element of " { $snippet "separators" } " and outputs an array of pieces. The pieces do not include the elements along which the sequence was split." }
77 { $examples { $example "USING: prettyprint splitting ;" "\"hello world-how are you?\" \" -\" split ." "{ \"hello\" \"world\" \"how\" \"are\" \"you?\" }" } } ;
78
79 HELP: ?head
80 { $values { "seq" sequence } { "begin" sequence } { "newseq" "a new sequence" } { "?" boolean } }
81 { $description "Tests if " { $snippet "seq" } " starts with " { $snippet "begin" } ". If there is a match, outputs the subrange of " { $snippet "seq" } " excluding " { $snippet "begin" } ", and " { $link t } ". If there is no match, outputs " { $snippet "seq" } " and " { $link f } "." } ;
82
83 HELP: ?head-slice
84 { $values { "seq" sequence } { "begin" sequence } { "newseq" slice } { "?" boolean } }
85 { $description "Like " { $link ?head } ", except the resulting sequence is a " { $link slice } "." } ;
86
87 HELP: ?tail
88 { $values { "seq" sequence } { "end" sequence } { "newseq" "a new sequence" } { "?" boolean } }
89 { $description "Tests if " { $snippet "seq" } " ends with " { $snippet "end" } ". If there is a match, outputs the subrange of " { $snippet "seq" } " excluding " { $snippet "end" } ", and " { $link t } ". If there is no match, outputs " { $snippet "seq" } " and " { $link f } "." } ;
90
91 HELP: ?tail-slice
92 { $values { "seq" sequence } { "end" sequence } { "newseq" slice } { "?" boolean } }
93 { $description "Like " { $link ?tail } ", except the resulting sequence is a " { $link slice } "." } ;
94
95 HELP: string-lines
96 { $values { "str" string } { "seq" { $sequence string } } }
97 { $description "Splits a string along line breaks." }
98 { $examples
99     { $example "USING: prettyprint splitting ;" "\"Hello\\r\\nworld\\n\" string-lines ." "{ \"Hello\" \"world\" }" }
100 } ;
101
102 HELP: replace
103 { $values { "seq" sequence } { "old" sequence } { "new" sequence } { "new-seq" sequence } }
104 { $description "Replaces every occurrence of " { $snippet "old" } " with " { $snippet "new" } " in the " { $snippet "seq" } "." }
105 { $examples
106     { $example "USING: io splitting ;"
107                "\"cool example is cool\" \"cool\" \"silly\" replace print"
108                "silly example is silly"
109     }
110 } ;