示例#1
0
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)
示例#2
0
def test_switch2(c, x, y):
    fn = switch(
        c,
        partial(scalar_sub, x),
        partial(scalar_add, x)
    )
    return fn(y)
示例#3
0
        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)
示例#4
0
    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)
示例#5
0
    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]
示例#6
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)
示例#7
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)
示例#8
0
 def before(x, y):
     cond = x < 0
     a = switch(cond, x, y)
     b = switch(cond, y, x)
     return a + b
示例#9
0
def test_prim_switch():
    assert switch(True, 1, 2) == 1
    assert switch(False, 1, 2) == 2
示例#10
0
def test_switch(c, x, y):
    return switch(c, x, y)
示例#11
0
 def before(x, y):
     return switch(False, x, y)
示例#12
0
 def before(x, y):
     return switch(True, x, y)
示例#13
0
 def before(x, y):
     return env_getitem(switch(x < 0, newenv, newenv), embed(y), 5)
示例#14
0
 def after(x, y):
     key = embed(y)
     return switch(x < 0, env_getitem(newenv, key, 5),
                   env_getitem(newenv, key, 5))
示例#15
0
 def before(x, y):
     return switch(x < 0, x, y)[0]
示例#16
0
 def after(x, y):
     return switch(x < 0, x[0], y[0])
示例#17
0
 def after(x, y):
     return switch(x < 0, x + y, y + x)
示例#18
0
def test_switch(c, x):
    return switch(c, scalar_usub, scalar_uadd)(x)
示例#19
0
 def before(x, y):
     a = y * y
     return switch(x < 0, a, a)
示例#20
0
 def before(a, b, c, d):
     x = a < 0
     y = b < 0
     return switch(x, switch(y, a, b), switch(y, c, d))
示例#21
0
 def after(a, b, c, d):
     x = a < 0
     return switch(x, a, d)