factor/core/splitting/splitting-docs.factor

100 lines
6.6 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
USING: help.markup help.syntax sequences strings ;
IN: splitting
ARTICLE: "sequences-split" "Splitting sequences"
"Splitting sequences at occurrences of subsequences:"
{ $subsections
?head
?head-slice
?tail
?tail-slice
split1
split1-slice
2012-04-18 18:55:15 -04:00
split1-when
split1-when-slice
split1-last
split1-last-slice
split
split-when
split-when-slice
}
2007-09-20 18:09:08 -04:00
"Splitting a string into lines:"
{ $subsections string-lines }
"Replacing subsequences with another subsequence:"
{ $subsections replace } ;
2007-09-20 18:09:08 -04:00
ABOUT: "sequences-split"
HELP: split1
2014-05-23 17:24:04 -04:00
{ $values { "seq" sequence } { "subseq" sequence } { "before" "a new sequence" } { "after" "a new sequence" } }
2007-09-20 18:09:08 -04:00
{ $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 } "." } ;
HELP: split1-slice
2014-05-23 17:24:04 -04:00
{ $values { "seq" sequence } { "subseq" sequence } { "before-slice" slice } { "after-slice" slice } }
{ $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 } "." } ;
2012-04-18 18:55:15 -04:00
HELP: split1-when
2014-05-23 17:24:04 -04:00
{ $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... ? ) } } { "before" "a new sequence" } { "after" "a new sequence" } }
2012-04-18 18:55:15 -04:00
{ $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." } ;
HELP: split1-when-slice
2014-05-23 17:24:04 -04:00
{ $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... ? ) } } { "before-slice" slice } { "after-slice" slice } }
{ $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 } "." } ;
HELP: split1-last
2014-05-23 17:24:04 -04:00
{ $values { "seq" sequence } { "subseq" sequence } { "before" "a new sequence" } { "after" "a new sequence" } }
2007-09-20 18:09:08 -04:00
{ $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 } "." } ;
HELP: split1-last-slice
2014-05-23 17:24:04 -04:00
{ $values { "seq" sequence } { "subseq" sequence } { "before-slice" slice } { "after-slice" slice } }
{ $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 } "." } ;
{ split1 split1-slice split1-last split1-last-slice } related-words
2007-09-20 18:09:08 -04:00
HELP: split-when
2014-05-23 17:24:04 -04:00
{ $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... ? ) } } { "pieces" "a new array" } }
{ $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." }
{ $examples { $example "USING: ascii kernel prettyprint splitting ;" "\"hello,world-how.are:you\" [ letter? not ] split-when ." "{ \"hello\" \"world\" \"how\" \"are\" \"you\" }" } } ;
HELP: split-when-slice
2014-05-23 17:24:04 -04:00
{ $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... ? ) } } { "pieces" "a new array" } }
{ $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." } ;
2007-09-20 18:09:08 -04:00
HELP: split
2014-05-23 17:24:04 -04:00
{ $values { "seq" sequence } { "separators" sequence } { "pieces" "a new array" } }
{ $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." }
2008-03-11 20:51:58 -04:00
{ $examples { $example "USING: prettyprint splitting ;" "\"hello world-how are you?\" \" -\" split ." "{ \"hello\" \"world\" \"how\" \"are\" \"you?\" }" } } ;
2007-09-20 18:09:08 -04:00
HELP: ?head
2014-05-23 17:24:04 -04:00
{ $values { "seq" sequence } { "begin" sequence } { "newseq" "a new sequence" } { "?" "a boolean" } }
2007-09-20 18:09:08 -04:00
{ $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 } "." } ;
HELP: ?head-slice
2014-05-23 17:24:04 -04:00
{ $values { "seq" sequence } { "begin" sequence } { "newseq" slice } { "?" "a boolean" } }
2007-09-20 18:09:08 -04:00
{ $description "Like " { $link ?head } ", except the resulting sequence is a " { $link slice } "." } ;
HELP: ?tail
2014-05-23 17:24:04 -04:00
{ $values { "seq" sequence } { "end" sequence } { "newseq" "a new sequence" } { "?" "a boolean" } }
2007-09-20 18:09:08 -04:00
{ $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 } "." } ;
HELP: ?tail-slice
2014-05-23 17:24:04 -04:00
{ $values { "seq" sequence } { "end" sequence } { "newseq" slice } { "?" "a boolean" } }
2007-09-20 18:09:08 -04:00
{ $description "Like " { $link ?tail } ", except the resulting sequence is a " { $link slice } "." } ;
HELP: string-lines
{ $values { "str" string } { "seq" "a sequence of strings" } }
{ $description "Splits a string along line breaks." }
{ $examples
2008-03-11 20:51:58 -04:00
{ $example "USING: prettyprint splitting ;" "\"Hello\\r\\nworld\\n\" string-lines ." "{ \"Hello\" \"world\" \"\" }" }
2007-09-20 18:09:08 -04:00
} ;
HELP: replace
{ $values { "seq" sequence } { "old" sequence } { "new" sequence } { "new-seq" sequence } }
{ $description "Replaces every occurrence of " { $snippet "old" } " with " { $snippet "new" } " in the " { $snippet "seq" } "." }
{ $examples
{ $example "USING: io splitting ;"
"\"cool example is cool\" \"cool\" \"silly\" replace print"
"silly example is silly"
}
} ;