[ prog / sol / mona ]

prog


Monads,Async/Await : Algebraic Effects in C99

28 2021-01-14 17:32

//its also possible to evaluate rnd() for each argument
//this would seem closer to the lisp version?
#include "Util/void.h"
#define roll(r) condelse("c",(r<0.3,"a"),(r>0.5,"b"))
#define roll2(r) condelse("c",(r<0.1,"a"),(r>0.3,"b"))
#define rollx(func) ({atype q1=__rdtsc();func(uintdouble01(randomize(q1))); })
#define rolly1(r,args...) ({ condelse(args);})
#define rolly(args...) ({ atype q1=__rdtsc();\
float r=(uintdouble01(randomize(q1)));\
rolly1(r,args) ;})

#define rndflt1() ({ atype q1=__rdtsc(); double res= uintdouble01(randomize(q1));res;})

#define prefix1(a) (rndflt1() detuple(a))
#define rollz(args...) condelse(first(args),chainapply(prefix1,rest(args)))
int main(){print(rollz("c",(<0.1,"a"),(>0.5,"b"),(<0.4,"e")) );}

69


VIP:

do not edit these