combinators.random: some style cleanup.

db4
John Benediktsson 2012-08-02 14:06:08 -07:00
parent 669367f29f
commit d3ce5c7deb
1 changed files with 12 additions and 9 deletions

View File

@ -6,7 +6,9 @@ summary ;
IN: combinators.random
: ifp ( p true false -- ) [ random-unit > ] 2dip if ; inline
: whenp ( p true -- ) [ ] ifp ; inline
: unlessp ( p false -- ) [ [ ] ] dip ifp ; inline
<PRIVATE
@ -41,7 +43,8 @@ MACRO: (casep) ( assoc -- ) (casep>quot) ;
(casep>quot) [ random-unit ] prepend ;
: (conditional-probabilities) ( seq i -- p )
[ dup 0 > [ head [ 1 swap - ] [ * ] map-reduce ] [ 2drop 1 ] if ] [ swap nth ] 2bi * ;
[ dup 0 > [ head [ 1 swap - ] [ * ] map-reduce ] [ 2drop 1 ] if ]
[ swap nth ] 2bi * ;
: conditional-probabilities ( seq -- seq' )
dup length iota [ (conditional-probabilities) ] with map ;