Exemplo n.º 1
0
def test_atom():
    """Ensure atom indicates atomicity."""
    env = prelude.env()

    assert env[wtypes.Symbol('atom?')].call([wtypes.Integer(1)],
                                            env) == wtypes.Bool(True)

    assert env[wtypes.Symbol('atom?')].call([quoted_list([wtypes.Integer(1)])],
                                            env) == wtypes.Bool(False)
Exemplo n.º 2
0
def test_equal():
    """Ensure equal tests equality properly."""
    assert prelude.env()[wtypes.Symbol('eq?')].call(
        [wtypes.Integer(4), wtypes.Integer(4)], {}) == wtypes.Bool(True)

    assert prelude.env()[wtypes.Symbol('eq?')].call(
        [wtypes.Integer(4), wtypes.Integer(2)], {}) == wtypes.Bool(False)

    assert prelude.env()[wtypes.Symbol('eq?')].call(
        [wtypes.Integer(4), wtypes.String('abc')], {}) == wtypes.Bool(False)
Exemplo n.º 3
0
def test_parse_list():
    """Ensure we can parse lists."""
    assert parser.parse_expr.parse('(1    abc "abc" #t #f +)') == wtypes.List([
        wtypes.Integer(1),
        wtypes.Symbol('abc'),
        wtypes.String('abc'),
        wtypes.Bool(True),
        wtypes.Bool(False),
        wtypes.Symbol('+'),
    ])
Exemplo n.º 4
0
def cond(args: typing.List[wtypes.Expression],
         env: wisp.env.Environment) -> wtypes.Expression:
    """Return the expression associated with the first test to return true."""
    for arg in args:
        if not isinstance(arg, wtypes.List):
            raise exceptions.WispException('invalid cond form: %s' % args)
        elif len(arg.items) != 2:
            raise exceptions.WispException('invalid cond form: %s' % args)

        body, test = arg.items
        if (test == wtypes.Symbol('else') or
                test.eval(env) == wtypes.Bool(True)):
            return body.eval(env)
    else:
        return wtypes.Symbol('unspecified return value')
Exemplo n.º 5
0
def test_eval_bool():
    """Ensure bools evaluate to themselves."""
    assert wtypes.Bool(True).eval({}) == wtypes.Bool(True)
Exemplo n.º 6
0
def test_parse_bool():
    """Ensure we can parse true and false."""
    assert parser.parse_expr.parse('#t') == wtypes.Bool(True)
    assert parser.parse_expr.parse('#f') == wtypes.Bool(False)
Exemplo n.º 7
0
def is_atom(args: typing.List[wtypes.Expression],
            env: wisp.env.Environment) -> wtypes.Bool:
    """Indicate whether we're passed a list or an atom."""
    return wtypes.Bool(not isinstance(args[0], wtypes.List))
Exemplo n.º 8
0
def is_equal(args: typing.List[wtypes.Expression],
             env: wisp.env.Environment) -> wtypes.Bool:
    """Return a boolean indicating if the two elements are equal."""
    return wtypes.Bool(args[0] == args[1])
Exemplo n.º 9
0
def parse_false():
    """Parse a boolean false from a #f lexeme."""
    yield parsec.string('#f')
    return wtypes.Bool(False)
Exemplo n.º 10
0
def parse_true():
    """Parse a boolean true from a #t lexeme."""
    yield parsec.string('#t')
    return wtypes.Bool(True)