From d653fc6500f5a09eb509edf7ad0599ab1632ddc1 Mon Sep 17 00:00:00 2001 From: Daniel Cerqueira Date: Mon, 17 Aug 2026 10:20:27 +0100 Subject: remove and > and < , primitives, add and <= and >=, primitives --- README.md | 6 +++--- examples/mandelbrot.lali | 4 ++-- liblali.c | 23 ++++++++--------------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 2bd4b8b..7f3492f 100644 --- a/README.md +++ b/README.md @@ -56,12 +56,12 @@ numbers) or by `-` (for negative numbers). There is support for the five arithmetic operations `+`, `-`, `*`, `/`, `%` (with `%` the operands are automatically converted to integer) as well as the relational -operations `<`, `>`: +operations `<=`, `>=`: (- +5) ; -5 (- +5 +3.2 +.6) ; +1.2 - (< +2 +4 +6.8) ; t - (> +4 +8) ; f + (<= +2 +4 +6.8 +6.8) ; t + (>= +4 +8) ; f #### Random number operation diff --git a/examples/mandelbrot.lali b/examples/mandelbrot.lali index 0268deb..ad3b74f 100644 --- a/examples/mandelbrot.lali +++ b/examples/mandelbrot.lali @@ -1,5 +1,5 @@ (defun for (from to func) - (cond ((< from to) (func from) (for (+ from +1) to func)))) + (cond ((not (>= from to)) (func from) (for (+ from +1) to func)))) (set 'mandelbrot-chars (list " " "." "," "`" "'" "\"" ":" ";" "-" "+" "o" "O" "0" "1" @@ -7,7 +7,7 @@ (defun mandelbrot-iter (x y x0 y0 i) (fill ((diff i +28) " ") - ((not (> (+ (* x0 x0) (* y0 y0)) +4)) (nth i mandelbrot-chars)) + ((<= (+ (* x0 x0) (* y0 y0)) +4) (nth i mandelbrot-chars)) (f (mandelbrot-iter x y (+ (- (* x0 x0) (* y0 y0)) x) (+ (* +2 x0 y0) y) (+ i +1))))) diff --git a/liblali.c b/liblali.c index 3636d4b..a8d8adc 100644 --- a/liblali.c +++ b/liblali.c @@ -1084,17 +1084,10 @@ DEFINE_PRIMITIVE_ARITHMETIC(primitiveRemainder, %, "+1", atoi, int, "%d", " /* DEFINE_PRIMITIVE_RELATIONAL(primitiveDifferent, !=, false) */ /* DEFINE_PRIMITIVE_RELATIONAL(primitiveEqual, ==, true) */ -DEFINE_PRIMITIVE_RELATIONAL(primitiveLess, <, true) -/* DEFINE_PRIMITIVE_RELATIONAL(primitiveLessEqual, <=, true) */ -DEFINE_PRIMITIVE_RELATIONAL(primitiveGreater, >, true) -/* DEFINE_PRIMITIVE_RELATIONAL(primitiveGreaterEqual, >=, true) */ - -bool hasADot(char *string) { - for (int i = 0; string[i] != '\0'; i++) - if (string[i] == '.') - return true; - return false; -} +/* DEFINE_PRIMITIVE_RELATIONAL(primitiveLess, <, true) */ +DEFINE_PRIMITIVE_RELATIONAL(primitiveLessEqual, <=, true) +/* DEFINE_PRIMITIVE_RELATIONAL(primitiveGreater, >, true) */ +DEFINE_PRIMITIVE_RELATIONAL(primitiveGreaterEqual, >=, true) Object *say(Object *object, GC_PARAM) { if ((object)->type != TYPE_SYMBOL && @@ -1338,10 +1331,10 @@ Primitive primitives[] = { { "%", 1, -1, primitiveRemainder }, /* { "=", 1, -1, primitiveEqual }, */ /* { "!", 1, -1, primitiveDifferent }, */ - { "<", 1, -1, primitiveLess }, - /* { "<=", 1, -1, primitiveLessEqual }, */ - { ">", 1, -1, primitiveGreater }, - /* { ">=", 1, -1, primitiveGreaterEqual } */ + /* { "<", 1, -1, primitiveLess }, */ + { "<=", 1, -1, primitiveLessEqual }, + /* { ">", 1, -1, primitiveGreater }, */ + { ">=", 1, -1, primitiveGreaterEqual }, { "join", 1, 1, primitiveJoin }, { "split", 1, 1, primitiveSplit }, }; -- cgit