Пример #1
0
def apply_primitive(name, vals):
    """Applies the primitive function `name`, with args=`vals`."""
    if is_eq(name, quote("cons")):
        return cons(first(vals), second(vals))

    if is_eq(name, quote("car")):
        return car(first(vals))

    if is_eq(name, quote("cdr")):
        return cdr(first(vals))

    if is_eq(name, quote("null?")):
        return is_null(first(vals))

    if is_eq(name, quote("eq?")):
        return is_eq(first(vals), second(vals))

    if is_eq(name, quote("atom?")):
        return _is_atom(first(vals))

    if is_eq(name, quote("zero?")):
        return is_zero(first(vals))

    if is_eq(name, quote("add1")):
        return add1(first(vals))

    if is_eq(name, quote("sub1")):
        return sub1(first(vals))

    if is_eq(name, quote("number?")):
        return is_number(first(vals))
Пример #2
0
def render_pair(asker, x):
    return asker.reply(answer=strings.concat(
        strings.concat(
            T.from_str("("),
            asker.ask_firmly(render(fields.get(pairs.first(), x))),
        ),
        strings.concat(
            T.from_str(", "),
            strings.concat(
                asker.ask_firmly(render(fields.get(pairs.first(), x))),
                T.from_str(")")
            )
        )
    ))
Пример #3
0
def itemize_cons(asker, head, tail):
    a = fields.get(asker, pairs.first(), head)
    b = fields.get(asker, pairs.second(), head)
    return asker.reply(answer=cons(a, b, from_items(tail)))
Пример #4
0
def is_non_primitive(l):
    """Asks the question if `l` is a primitive."""
    return is_eq(first(l), quote("non-primitive"))