add the %chance combinator
parent
bd8dcd4e0a
commit
107cadf604
|
@ -11,3 +11,12 @@ HELP: generate
|
|||
"[ 20 random-prime ] [ 4 mod 3 = ] generate ."
|
||||
"526367"
|
||||
} ;
|
||||
|
||||
HELP: %chance
|
||||
{ $values { "quot" quotation } { "n" integer } }
|
||||
{ $description "Calls the quotation " { $snippet "n" } " percent of the time." }
|
||||
{ $unchecked-example
|
||||
"USING: io ;"
|
||||
"[ \"hello, world! maybe.\" print ] 50 %chance"
|
||||
""
|
||||
} ;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: kernel combinators fry namespaces quotations hashtables
|
||||
sequences assocs arrays inference effects math math.ranges
|
||||
generalizations macros continuations locals ;
|
||||
generalizations macros continuations random locals ;
|
||||
|
||||
IN: combinators.lib
|
||||
|
||||
|
@ -147,3 +147,5 @@ MACRO: predicates ( seq -- quot/f )
|
|||
dup [ 1quotation [ drop ] prepend ] map
|
||||
>r [ [ dup ] prepend ] map r> zip [ drop f ] suffix
|
||||
[ cond ] curry ;
|
||||
|
||||
: %chance ( quot integer -- ) 100 random > swap when ; inline
|
||||
|
|
Loading…
Reference in New Issue