1 ! Copyright (C) 2010 Jon Harper.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs help.markup help.syntax kernel quotations
4 combinators.random.private sequences ;
8 { $values { "seq" "a sequence of quotations" } }
9 { $description "Calls a random quotation from the given sequence of quotations." } ;
12 { $values { "seq" "a sequence of words" } }
13 { $description "Executes a random word from the given sequence of quotations." } ;
17 { "p" "a number between 0 and 1" } { "true" quotation } { "false" quotation }
19 { $description "Calls the " { $snippet "true" } " quotation with probability " { $snippet "p" }
20 " and the " { $snippet "false" } " quotation with probability (1-" { $snippet "p" } ")." } ;
24 { "assoc" "a sequence of probability/quotations pairs with an optional quotation at the end" }
26 { $description "Calls the different quotations randomly with the given probability. The optional quotation at the end "
27 "will be given a probability so that the sum of the probabilities is one. Therefore, the sum of the probabilities "
28 "must be exactly one when no default quotation is given, or between zero and one when it is given. "
29 "Additionally, all probabilities must be numbers between 0 and 1. "
30 "These rules are enforced during the macro expansion by throwing " { $link bad-probabilities } " "
31 "if they are not respected." }
33 "The following two forms will output 1 with 0.2 probability, 2 with 0.3 probability and 3 with 0.5 probability"
35 "USING: combinators.random ;"
38 " { 0.5 [ 3 ] } } casep ."
42 "USING: combinators.random ;"
45 " { [ 3 ] } } casep ."
50 { $see-also casep* } ;
54 { "assoc" "a sequence of probability/word pairs with an optional quotation at the end" }
56 { $description "Calls the different quotations randomly with the given probability. Unlike " { $link casep } ", "
57 "the probabilities are interpreted as conditional probabilities. "
58 "All probabilities must be numbers between 0 and 1. "
59 "The sequence must end with a pair whose probability is one, or a quotation."
60 "These rules are enforced during the macro expansion by throwing " { $link bad-probabilities } " "
61 "if they are not respected." }
63 "The following two forms will output 1 with 0.5 probability, 2 with 0.25 probability and 3 with 0.25 probability"
65 "USING: combinators.random ;"
68 " { 1 [ 3 ] } } casep* ."
72 "USING: combinators.random ;"
75 " { [ 3 ] } } casep* ."
83 { "p" "a number between 0 and 1" } { "false" quotation }
85 { $description "Variant of " { $link ifp } " with no " { $snippet "true" } " quotation." } ;
89 { "p" "a number between 0 and 1" } { "true" quotation }
91 { $description "Variant of " { $link ifp } " with no " { $snippet "false" } " quotation." } ;
93 ARTICLE: "combinators.random" "Random combinators"
94 "The " { $vocab-link "combinators.random" } " vocabulary implements simple combinators to easily express random choices"
95 " between multiple code paths."
97 "For all these combinators, the stack effect of the different given quotations or words must be the same."
99 "Variants of if, when and unless:"
112 ABOUT: "combinators.random"