示例#1
0
文件: syntax.py 项目: mbillingr/sdf
def if_alternative(exp):
    if is_null(cdddr(exp)):
        return Symbol("the-unspecified-value")
    else:
        return cadddr(exp)
示例#2
0
文件: syntax.py 项目: mbillingr/sdf
def make_begin(actions):
    return cons(Symbol("begin"), actions)
示例#3
0
文件: syntax.py 项目: mbillingr/sdf
def is_if(exp):
    return is_tagged_list(exp, Symbol("if"))
示例#4
0
文件: syntax.py 项目: mbillingr/sdf
def make_lambda(parameters, body):
    return cons(
        Symbol("lambda"),
        cons(parameters,
             begin_actions(body) if is_begin(body) else (body, )),
    )
示例#5
0
文件: syntax.py 项目: mbillingr/sdf
def is_begin(exp):
    return is_tagged_list(exp, Symbol("begin"))
示例#6
0
文件: syntax.py 项目: mbillingr/sdf
def is_definition(exp):
    return is_tagged_list(exp, Symbol("define"))
示例#7
0
文件: syntax.py 项目: mbillingr/sdf
def is_lambda(exp):
    return is_tagged_list(exp, Symbol("lambda"))
示例#8
0
文件: syntax.py 项目: mbillingr/sdf
def is_assignment(exp):
    return is_tagged_list(exp, Symbol("set!"))
示例#9
0
文件: syntax.py 项目: mbillingr/sdf
def is_undoable_assignment(exp):
    return is_tagged_list(exp, Symbol("maybe-set!"))
示例#10
0
文件: syntax.py 项目: mbillingr/sdf
def make_if(pred, conseq, alternative):
    return Symbol("if"), pred, conseq, alternative
示例#11
0
def is_cond(exp):
    return is_tagged_list(exp, Symbol("cond"))
示例#12
0
def is_let(exp):
    return is_tagged_list(exp, Symbol("let"))
示例#13
0
def is_else_clause(clause):
    return cond_clause_predicate(clause) == Symbol("else")
示例#14
0
THE_GLOBAL_ENVIRONMENT = "not initialized"


def initialize_repl():
    global THE_GLOBAL_ENVIRONMENT
    THE_GLOBAL_ENVIRONMENT = make_initial_environment()


def check_repl_initialized():
    if THE_GLOBAL_ENVIRONMENT == "not initialized":
        raise RuntimeError("Interpreter not initialized. Run init() first.")


if __name__ == "__main__":
    a = Symbol("a")
    b = Symbol("b")
    c = Symbol("c")

    print((a, b, c))

    print(car((1, 2, 3)), cdr((1, 2, 3)))
    x = cons(1, (2, 3, 4))
    print(x)
    print(car(x), cdr(x), cdr(cdr(x)))

    quote = Symbol("quote")
    x = Symbol("x")
    begin = Symbol("begin")

    # print(g.eval(((Symbol('lambda'), (x,), x), 42), ()))