Esempio n. 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))
Esempio n. 2
0
def t_const(exp, table):
    """`t_const` type function: `*const` in schmeme."""
    if is_number(exp):
        return exp

    if is_eq(exp, quote("True")):
        return True

    if is_eq(exp, quote("False")):
        return False

    return build(quote("primitive", exp))
Esempio n. 3
0
def no_nums(l):
    """Remove all the numbers in the list `l`."""
    if is_null(l):
        return quote()

    elif is_atom(car(l)):
        if is_number(car(l)):
            return no_nums(cdr(l))

        else:
            return cons(car(l), (no_nums(cdr(l))))

    else:
        return cons(no_nums(car(l)), no_nums(cdr(l)))
Esempio n. 4
0
def all_nums(l):
    """Return all numbers from list `l`."""
    if is_null(l):
        return quote()

    elif is_atom(car(l)):

        if is_number(car(l)):
            return cons(car(l), all_nums(cdr(l)))

        else:
            return all_nums(cdr(l))

    else:
        return cons(all_nums(car(l)), all_nums(cdr(l)))