def test_switch_switch(x, y): def f1(z): return z > 0 def f2(z): return z < 0 f = switch(x > 0, f1, f2) return switch(f(y), 1, 2)
def test_switch2(c, x, y): fn = switch( c, partial(scalar_sub, x), partial(scalar_add, x) ) return fn(y)
def after_helper(x, y, z): def tb(y, z): return scalar_mul(y, z) def fb(y, z): return scalar_add(y, z) return switch(x < 0, tb, fb)(y, z)
def after(x, y): def f1(x, y): return x * y def f2(x, y): return x + y return switch(x < 0, f1, f2)(x, y)
def before(x, y): def f1(x, y): return x, y def f2(x, y): return y, x return switch(x < 0, f1, f2)(x, y)[0]
def before(x, y): key = embed(x) def f1(x, y): return env_setitem(newenv, key, x * y) def f2(x, y): return env_setitem(newenv, key, x + y) return env_getitem(switch(x < 0, f1, f2)(x, y), key, 0)
def test_closure_in_data(c, x): def f(x): return x * x def g(x): return x + x a = Thing((1, [f])) b = Thing((2, [g])) i, h = switch(c, a, b).contents return h[0](x)
def before(x, y): cond = x < 0 a = switch(cond, x, y) b = switch(cond, y, x) return a + b
def test_prim_switch(): assert switch(True, 1, 2) == 1 assert switch(False, 1, 2) == 2
def test_switch(c, x, y): return switch(c, x, y)
def before(x, y): return switch(False, x, y)
def before(x, y): return switch(True, x, y)
def before(x, y): return env_getitem(switch(x < 0, newenv, newenv), embed(y), 5)
def after(x, y): key = embed(y) return switch(x < 0, env_getitem(newenv, key, 5), env_getitem(newenv, key, 5))
def before(x, y): return switch(x < 0, x, y)[0]
def after(x, y): return switch(x < 0, x[0], y[0])
def after(x, y): return switch(x < 0, x + y, y + x)
def test_switch(c, x): return switch(c, scalar_usub, scalar_uadd)(x)
def before(x, y): a = y * y return switch(x < 0, a, a)
def before(a, b, c, d): x = a < 0 y = b < 0 return switch(x, switch(y, a, b), switch(y, c, d))
def after(a, b, c, d): x = a < 0 return switch(x, a, d)