From 5383dfac9cfc519c5f1651d18edb374d6fce4e6f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C5=99emysl=20Janouch?=
Date: Sun, 21 May 2017 12:07:21 +0200
Subject: [PATCH] Add "ne?", "ge?", "le?", "gt?"
At least in some form.
---
ell.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/ell.c b/ell.c
index 8a46c6b..301d17e 100755
--- a/ell.c
+++ b/ell.c
@@ -1145,6 +1145,7 @@ defn (fn_not) {
return check (ctx, (*result = new_boolean (!truthy (args))));
}
+// TODO: "and" and "or" should be short-circuiting special forms
defn (fn_and) {
bool res = true;
for (; args; args = args->next)
@@ -1196,9 +1197,13 @@ init_runtime_library (struct context *ctx) {
const char *name; ///< Name of the function
const char *definition; ///< The defining script
} functions[] = {
- // TODO: try to think of something useful
// FIXME: this "unless" is probably not going to work
- { "unless", "arg cond body; if (not (eval @cond)) @body" },
+ { "unless", "arg _cond _body; if (not (eval @_cond)) @_body" },
+ // TODO: we should be able to apply them to all arguments
+ { "ne?", "arg _ne1 _ne2; not (eq? @_ne1 @_ne2))" },
+ { "ge?", "arg _ge1 _ge2; not (lt? @_ge1 @_ge2))" },
+ { "le?", "arg _le1 _le2; ge? @_le2 @_le1" },
+ { "gt?", "arg _gt1 _gt2; lt? @_gt2 @_gt1" },
};
bool ok = true;