Improve support for functions #1

This commit is contained in:
Bartłomiej Pluta
2019-07-04 02:09:24 +02:00
parent c8ff5ce38f
commit 6390ac20de
31 changed files with 514 additions and 328 deletions

View File

@@ -0,0 +1,17 @@
import random as r
def random(args, env):
if not all(isinstance(x, list) and len(x) == 2 and isinstance(x[0], float) for x in args):
return # not valid signature
if sum([x[0] for x in args]) != 1.0:
return # not sums to 100%
choice = r.random()
acc = 0
for e in args:
acc += e[0]
if choice <= acc:
return e[1]
#TODO: sample