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))
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(")") ) ) ))
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)))
def is_non_primitive(l): """Asks the question if `l` is a primitive.""" return is_eq(first(l), quote("non-primitive"))