How to use the amplify.message.Message function in amplify

To help you get started, we’ve selected a few amplify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github paulfchristiano / alba / amplify / meta.py View on Github external
def decode_char(x, H):
    agent = H
    code, agent = agent.act(Message("what is the ASCII code of []?", x))
    return chr(decode_int(code, H))
github paulfchristiano / alba / amplify / meta.py View on Github external
def encode_int(x):
    if x == 0:
        return Message("zero")
    elif x < 0:
        return Message("the additive inverse of []", encode_int(-x))
    elif x%2 == 0:
        return Message("two times []", encode_int(x/2))
    elif x%2 == 1:
        return Message("two times [] plus one", encode_int(x/2))
    raise Exception()
github paulfchristiano / alba / amplify / meta.py View on Github external
sign = -1
        x = -x
    elif signm == Message("positive"):
        sign = 1
    elif signm == Message("zero"):
        return 0
    else:
        raise Exception("sign is not 'negative', 'positive', or 'zero'")
    paritym, agent  = agent.act(Message("is it even or odd? (respond verbatim)"))
    if paritym == Message("even"):
        parity = 0
    elif paritym == Message("odd"):
        parity = 1
    else:
        raise Exception("Parity is not 'even' or 'odd'")
    half, agent = agent.act(Message("what is half of it, rounded towards zero?"))
    return sign * (2 * decode_int(half, H) + parity)
github paulfchristiano / alba / amplify / meta.py View on Github external
def encode_int(x):
    if x == 0:
        return Message("zero")
    elif x < 0:
        return Message("the additive inverse of []", encode_int(-x))
    elif x%2 == 0:
        return Message("two times []", encode_int(x/2))
    elif x%2 == 1:
        return Message("two times [] plus one", encode_int(x/2))
    raise Exception()
github paulfchristiano / alba / amplify / meta.py View on Github external
def decode_int(x, H):
    agent = H
    signm, agent = agent.act(Message("is [] negative, zero, or positive? (respond verbatim)", x))
    if signm == Message("negative"):
        sign = -1
        x = -x
    elif signm == Message("positive"):
        sign = 1
    elif signm == Message("zero"):
        return 0
    else:
        raise Exception("sign is not 'negative', 'positive', or 'zero'")
    paritym, agent  = agent.act(Message("is it even or odd? (respond verbatim)"))
    if paritym == Message("even"):
        parity = 0
    elif paritym == Message("odd"):
        parity = 1
    else:
        raise Exception("Parity is not 'even' or 'odd'")
    half, agent = agent.act(Message("what is half of it, rounded towards zero?"))
    return sign * (2 * decode_int(half, H) + parity)
github paulfchristiano / alba / amplify / meta.py View on Github external
def decode_int(x, H):
    agent = H
    signm, agent = agent.act(Message("is [] negative, zero, or positive? (respond verbatim)", x))
    if signm == Message("negative"):
        sign = -1
        x = -x
    elif signm == Message("positive"):
        sign = 1
    elif signm == Message("zero"):
        return 0
    else:
        raise Exception("sign is not 'negative', 'positive', or 'zero'")
    paritym, agent  = agent.act(Message("is it even or odd? (respond verbatim)"))
    if paritym == Message("even"):
        parity = 0
    elif paritym == Message("odd"):
        parity = 1
    else:
        raise Exception("Parity is not 'even' or 'odd'")
    half, agent = agent.act(Message("what is half of it, rounded towards zero?"))
    return sign * (2 * decode_int(half, H) + parity)
github paulfchristiano / alba / amplify / meta.py View on Github external
def decode_list(x, H):
    agent = H
    empty, agent = agent.act(Message("is [] empty? (respond yes/no)", x))
    if empty == Message("yes"):
        return []
    elif empty == Message("no"):
        x, agent = agent.act(Message("what is its first element?"))
        xs, agent = agent.act(Message("what is the list of remaining elements?"))
        return [x] + decode_list(xs, H)
    else:
        raise Exception("is empty is not 'yes' or 'no'")
github paulfchristiano / alba / amplify / meta.py View on Github external
def decode_int(x, H):
    agent = H
    signm, agent = agent.act(Message("is [] negative, zero, or positive? (respond verbatim)", x))
    if signm == Message("negative"):
        sign = -1
        x = -x
    elif signm == Message("positive"):
        sign = 1
    elif signm == Message("zero"):
        return 0
    else:
        raise Exception("sign is not 'negative', 'positive', or 'zero'")
    paritym, agent  = agent.act(Message("is it even or odd? (respond verbatim)"))
    if paritym == Message("even"):
        parity = 0
    elif paritym == Message("odd"):
        parity = 1
    else:
        raise Exception("Parity is not 'even' or 'odd'")
github paulfchristiano / alba / amplify / meta.py View on Github external
def encode_char(x):
    code = encode_int(ord(x))
    return Message("the character with ASCII code []", code)