return result;
}
+static struct EvalResult length(Gc *gc, struct Expr scope, struct Expr obj)
+{
+ if (!list_p(obj)) {
+ return eval_failure(list(gc, 3,
+ SYMBOL(gc, "wrong-argument-type"),
+ SYMBOL(gc, "listp"),
+ obj),
+ scope);
+ }
+
+ long int count = 0;
+
+ while (!nil_p(obj)) {
+ count++;
+ obj = obj.cons->cdr;
+ }
+
+ return eval_success(NUMBER(gc, count), scope);
+}
+
static struct EvalResult eval_atom(Gc *gc, struct Expr scope, struct Atom *atom)
{
(void) scope;
return args;
}
return plus_op(gc, args.expr, scope);
+ } else if (strcmp(cons->car.atom->sym, "set") == 0) {
+ struct Expr args = cons->cdr;
+ struct EvalResult n = length(gc, scope, args);
+
+ if (n.is_error) {
+ return n;
+ }
+ scope = n.scope;
+
+ if (n.expr.atom->num != 2) {
+ return eval_failure(list(gc, 3,
+ SYMBOL(gc, "wrong-number-of-arguments"),
+ SYMBOL(gc, "set"),
+ NUMBER(gc, n.expr.atom->num)),
+ scope);
+ }
+
+ struct Expr name = args.cons->car;
+ if (!symbol_p(name)) {
+ return eval_failure(list(gc, 3,
+ SYMBOL(gc, "wrong-type-argument"),
+ SYMBOL(gc, "symbolp"),
+ name),
+ scope);
+ }
+
+ struct EvalResult value = eval(gc, scope, args.cons->cdr.cons->car);
+ if (value.is_error) {
+ return value;
+ }
+ scope = value.scope;
+
+ return eval_success(value.expr, set_scope_value(gc, scope, name, value.expr));
}
return eval_failure(CONS(gc,