[ prog / sol / mona ]

prog


Monads,Async/Await : Algebraic Effects in C99

30 2021-01-14 19:49

//i've updated headers to introduce condifelse(more versatile version of ternary expression nesting) and this is the result:
#include "Util/void.h"
#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)))

#define prefix2(a) (rndflt1() detuple(a) )
#define rolls(args...) condifelse(fprint(stderr,"Error:Nothing matched"),chainapply(prefix2,args))
int main(){
#define symbol1 "A string"
#define symbol2 200.5
#define symbol3 (char)'e'
#define symbol4 12 //default
//print is variadic, the macro just demonstrate you can include
anything in the rest of the tuple;
rolls(
(<0.1,print("Probability 10%:"),print(symbol1)),
(>0.8,print("Probability 20%:"),print(symbol2)),
(<0.15,print("Probability 15%:"),print(symbol3)),
(<0.5,print("Probability 50%:"),print(symbol4)));
;}

69


VIP:

do not edit these