1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-13 17:06:49 +00:00

Fix not= and odd?

This commit is contained in:
Calvin Rose 2018-07-08 11:31:24 -04:00
parent f63d08efbd
commit 08f6c642d0
3 changed files with 10 additions and 6 deletions

View File

@ -50,7 +50,7 @@
# Basic predicates
(defn even? [x] (== 0 (% x 2)))
(defn odd? [x] (== 1 (% x 2)))
(defn odd? [x] (not= 0 (% x 2)))
(defn zero? [x] (== x 0))
(defn pos? [x] (> x 0))
(defn neg? [x] (< x 0))

View File

@ -159,20 +159,20 @@ static int dst_strict_equal(DstArgs args) {
int32_t i;
for (i = 0; i < args.n - 1; i++) {
if (!dst_equals(args.v[i], args.v[i+1])) {
DST_RETURN(args, dst_wrap_false());
DST_RETURN_FALSE(args);
}
}
DST_RETURN(args, dst_wrap_true());
DST_RETURN_TRUE(args);
}
static int dst_strict_notequal(DstArgs args) {
int32_t i;
for (i = 0; i < args.n - 1; i++) {
if (dst_equals(args.v[i], args.v[i+1])) {
DST_RETURN(args, dst_wrap_false());
if (!dst_equals(args.v[i], args.v[i+1])) {
DST_RETURN_TRUE(args);
}
}
DST_RETURN(args, dst_wrap_true());
DST_RETURN_FALSE(args);
}
static int dst_not(DstArgs args) {

View File

@ -198,4 +198,8 @@
(def xs (apply1 tuple (for [x :range [0 10] :when (even? x)] (tuple (/ x 2) x))))
(assert (= xs '((0 0) (1 2) (2 4) (3 6) (4 8))) "for macro 1")
# Some testing for not=
(assert (not= 1 1 0) "not= 1")
(assert (not= 0 1 1) "not= 2")
(end-suite)