commit 44853b0e1d71254e0bf2aee93e9a4ca9476cc10b
parent 5a0bcbefc6e60e201276019a137e7891d4587d49
Author: NunoSempere <nuno.sempere@protonmail.com>
Date: Tue, 9 May 2023 23:10:06 -0400
add comparator function
Diffstat:
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/mumble b/mumble
Binary files differ.
diff --git a/src/mumble.c b/src/mumble.c
@@ -876,6 +876,25 @@ lispval* builtin_equal(lispval* v, lispenv* e)
}
+lispval* builtin_greater_than(lispval* v, lispenv* e)
+{
+ // ifelse 1 {a} b
+ LISPVAL_ASSERT(v->count == 2, "Error: function = takes two numeric arguments. Try (= 1 2)");
+
+ lispval* a = v->cell[0];
+ lispval* b = v->cell[1];
+
+ LISPVAL_ASSERT(a->type == LISPVAL_NUM, "Error: Functio = only takes numeric arguments.");
+ LISPVAL_ASSERT(b->type == LISPVAL_NUM, "Error: Functio = only takes numeric arguments.");
+
+ if(a->num > b->num){
+ return lispval_num(1);
+ }else {
+ return lispval_num(0);
+ }
+}
+
+
// Simple math ops
lispval* builtin_math_ops(char* op, lispval* v, lispenv* e)
{
@@ -977,6 +996,7 @@ void lispenv_add_builtins(lispenv* env)
lispenv_add_builtin("@", builtin_define_lambda, env);
lispenv_add_builtin("ifelse", builtin_ifelse, env);
lispenv_add_builtin("=", builtin_equal, env);
+ lispenv_add_builtin(">", builtin_greater_than, env);
}
// Evaluate the lispval