Example #1
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
Example #2
0
def types(a,b):
    """what are the types of [a] and [b]?"""
    type(a)
    with pydwimmer.builtin.core.probably(A):
        type(b)
        with pydwimmer.builtin.core.probably(A2):
            core.eq(A, A2)
            with pydwimmer.builtin.core.answer(A3):
                A3
                with pydwimmer.builtin.bools.yes():
                    raise both_probably_type(A2)
        with pydwimmer.builtin.core.answer(A2):
            core.eq(A, A2)
            with pydwimmer.builtin.core.answer(A3):
                A3
                with pydwimmer.builtin.bools.yes():
                    raise both_probably_type(A2)
    with pydwimmer.builtin.core.answer(A):
        type(b)
        with pydwimmer.builtin.core.probably(A2):
            core.eq(A, A2)
            with pydwimmer.builtin.core.answer(A3):
                A3
                with pydwimmer.builtin.bools.yes():
                    raise both_probably_type(A2)
        with pydwimmer.builtin.core.answer(A2):
            core.eq(A, A2)
            with pydwimmer.builtin.core.answer(A3):
                A3
                with pydwimmer.builtin.bools.yes():
                    raise both_probably_type(A2)