+ return ao_lisp_math(cons, builtin_mod);
+}
+
+ao_poly
+ao_lisp_compare(struct ao_lisp_cons *cons, enum ao_lisp_builtin_id op)
+{
+ ao_poly left;
+
+ if (!cons)
+ return _ao_lisp_atom_t;
+
+ left = cons->car;
+ cons = ao_lisp_poly_cons(cons->cdr);
+ while (cons) {
+ ao_poly right = cons->car;
+
+ if (op == builtin_equal) {
+ if (left != right)
+ return AO_LISP_NIL;
+ } else {
+ uint8_t lt = ao_lisp_poly_type(left);
+ uint8_t rt = ao_lisp_poly_type(right);
+ if (lt == AO_LISP_INT && rt == AO_LISP_INT) {
+ int l = ao_lisp_poly_int(left);
+ int r = ao_lisp_poly_int(right);
+
+ switch (op) {
+ case builtin_less:
+ if (!(l < r))
+ return AO_LISP_NIL;
+ break;
+ case builtin_greater:
+ if (!(l > r))
+ return AO_LISP_NIL;
+ break;
+ case builtin_less_equal:
+ if (!(l <= r))
+ return AO_LISP_NIL;
+ break;
+ case builtin_greater_equal:
+ if (!(l >= r))
+ return AO_LISP_NIL;
+ break;
+ default:
+ break;
+ }
+ } else if (lt == AO_LISP_STRING && rt == AO_LISP_STRING) {
+ int c = strcmp(ao_lisp_poly_string(left),
+ ao_lisp_poly_string(right));
+ switch (op) {
+ case builtin_less:
+ if (!(c < 0))
+ return AO_LISP_NIL;
+ break;
+ case builtin_greater:
+ if (!(c > 0))
+ return AO_LISP_NIL;
+ break;
+ case builtin_less_equal:
+ if (!(c <= 0))
+ return AO_LISP_NIL;
+ break;
+ case builtin_greater_equal:
+ if (!(c >= 0))
+ return AO_LISP_NIL;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ left = right;
+ cons = ao_lisp_poly_cons(cons->cdr);
+ }
+ return _ao_lisp_atom_t;
+}
+
+ao_poly
+ao_lisp_equal(struct ao_lisp_cons *cons)
+{
+ return ao_lisp_compare(cons, builtin_equal);
+}
+
+ao_poly
+ao_lisp_less(struct ao_lisp_cons *cons)
+{
+ return ao_lisp_compare(cons, builtin_less);
+}
+
+ao_poly
+ao_lisp_greater(struct ao_lisp_cons *cons)
+{
+ return ao_lisp_compare(cons, builtin_greater);
+}
+
+ao_poly
+ao_lisp_less_equal(struct ao_lisp_cons *cons)
+{
+ return ao_lisp_compare(cons, builtin_less_equal);
+}
+
+ao_poly
+ao_lisp_greater_equal(struct ao_lisp_cons *cons)
+{
+ return ao_lisp_compare(cons, builtin_greater_equal);