3 static struct Expr find_frame_with_name(struct Expr scope, struct Expr name)
5 struct Expr frame = scope;
7 while (cons_p(frame)) {
8 if (!nil_p(assoc(name, frame))) {
12 frame = frame.cons->car;
16 return scope.cons->car;
22 struct Expr empty_scope(void)
24 return CONS(NIL, NIL); /* '(()) */
27 struct Expr get_scope_value(struct Expr scope, struct Expr name)
31 struct Expr value = assoc(name, scope.cons->car);
32 return nil_p(value) ? get_scope_value(scope.cons->cdr, name) : value;
40 void set_scope_value(struct Expr scope, struct Expr name, struct Expr value)
42 struct Expr frame = find_frame_with_name(scope, name);
43 push(CONS(name, value), frame);
46 struct Expr push_scope_frame(struct Expr scope)
48 return CONS(empty_scope(), scope);
51 struct Expr pop_scope_frame(struct Expr scope)
53 if (scope.type == EXPR_CONS) {
54 return scope.cons->cdr;