Beispiel #1
0
def add(x, y):
    """what is [x] plus [y]?"""
    x
    with double(z):
        y
        with double(w):
            return double(z + w)
        with double_inc(w):
            return double_inc(z+w)
        with zero():
            return x
        with pydwimmer.builtin.ints.negative(x2):
            x2
            with pydwimmer.builtin.ints.double_inc(x3):
                decrement(double(minus(z, x3)))
                with core.answer(result):
                    return result
    with double_inc(z):
        y
        with double(w):
            return double_inc(z+w)
        with double_inc(w):
            return double(inc(z+w))
        with zero():
            return x
        with pydwimmer.builtin.ints.negative(x2):
            x2
    with zero():
        return y
    with pydwimmer.builtin.strings.string(chars):
        y
        with pydwimmer.builtin.strings.string(chars2):
Beispiel #2
0
def lookup(key, d):
    """what is the image of [key] in the dictionary [d]?"""
    d
    with empty_dict():
        raise no_image()
    with dict_cons(k, v, other):
        if core.eq(k, key):
            return key
        else:
            lookup(key, other)
            with core.answer(z):
                return z
            with no_image():
                raise no_image()
    with by_parity(evens, odds):
        parity(key)
        with odd_and_half_is(x):
            lookup(x, odds)
            with pydwimmer.builtin.core.answer(A):
                return A
    with dict_only(k, v):
        core.eq(k, key)
        with pydwimmer.builtin.core.answer(A):
            A
            with pydwimmer.builtin.bools.yes():
                return v