altos/lisp: Fix pairp builtin
authorKeith Packard <keithp@keithp.com>
Fri, 1 Dec 2017 10:31:29 +0000 (11:31 +0100)
committerKeith Packard <keithp@keithp.com>
Fri, 1 Dec 2017 10:31:29 +0000 (11:31 +0100)
Pairs are non-nil cons values; add an explicit check for nil here

Signed-off-by: Keith Packard <keithp@keithp.com>
src/lisp/ao_lisp_builtin.c

index 693cc3ca9bd0f6a97a2732b50a2c36b2c08698f1..f13f2180684481dc0f245dbb2f3148795a10b974 100644 (file)
@@ -675,7 +675,13 @@ ao_lisp_do_typep(int type, struct ao_lisp_cons *cons)
 ao_poly
 ao_lisp_do_pairp(struct ao_lisp_cons *cons)
 {
-       return ao_lisp_do_typep(AO_LISP_CONS, cons);
+       ao_poly v;
+       if (!ao_lisp_check_argc(_ao_lisp_atom_led, cons, 1, 1))
+               return AO_LISP_NIL;
+       v = ao_lisp_arg(cons, 0);
+       if (v != AO_LISP_NIL && ao_lisp_poly_type(v) == AO_LISP_CONS)
+               return _ao_lisp_bool_true;
+       return _ao_lisp_bool_false;
 }
 
 ao_poly