summaryrefslogtreecommitdiff
path: root/src/lisp/ao_lisp_builtin.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2017-12-01 15:40:23 -0600
committerKeith Packard <keithp@keithp.com>2017-12-01 15:40:23 -0600
commitc31744299e5a4342bbe26d3735ee2d8f09192ae9 (patch)
tree108153f1d01c56800d6e4dc0c56dbcce979717be /src/lisp/ao_lisp_builtin.c
parent98923ae1189f062b8b94120d47a56892db25493f (diff)
altos/lisp: split set/def. Add def support to lambdas
In scheme, set can only re-define existing variables while def cannot redefine existing variables in lambda context. Def within lambda creates a new variable at the nearest enclosing scope. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/lisp/ao_lisp_builtin.c')
-rw-r--r--src/lisp/ao_lisp_builtin.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/lisp/ao_lisp_builtin.c b/src/lisp/ao_lisp_builtin.c
index f13f2180..d4751ac2 100644
--- a/src/lisp/ao_lisp_builtin.c
+++ b/src/lisp/ao_lisp_builtin.c
@@ -208,6 +208,17 @@ ao_lisp_do_set(struct ao_lisp_cons *cons)
}
ao_poly
+ao_lisp_do_def(struct ao_lisp_cons *cons)
+{
+ if (!ao_lisp_check_argc(_ao_lisp_atom_def, cons, 2, 2))
+ return AO_LISP_NIL;
+ if (!ao_lisp_check_argt(_ao_lisp_atom_def, cons, 0, AO_LISP_ATOM, 0))
+ return AO_LISP_NIL;
+
+ return ao_lisp_atom_def(ao_lisp_arg(cons, 0), ao_lisp_arg(cons, 1));
+}
+
+ao_poly
ao_lisp_do_setq(struct ao_lisp_cons *cons)
{
ao_poly name;
@@ -216,7 +227,7 @@ ao_lisp_do_setq(struct ao_lisp_cons *cons)
name = cons->car;
if (ao_lisp_poly_type(name) != AO_LISP_ATOM)
return ao_lisp_error(AO_LISP_INVALID, "set! of non-atom");
- if (!ao_lisp_atom_ref(ao_lisp_frame_current, name))
+ if (!ao_lisp_atom_ref(name))
return ao_lisp_error(AO_LISP_INVALID, "atom not defined");
return ao_lisp__cons(_ao_lisp_atom_set,
ao_lisp__cons(ao_lisp__cons(_ao_lisp_atom_quote,