diff options
| author | Daniel Cerqueira <dan.git@lispclub.com> | 2026-08-17 10:20:27 +0100 |
|---|---|---|
| committer | Daniel Cerqueira <dan.git@lispclub.com> | 2026-08-17 10:26:21 +0100 |
| commit | d653fc6500f5a09eb509edf7ad0599ab1632ddc1 (patch) | |
| tree | 2a9d87d655f43e6d51b9dbef68015bea287b1bdb | |
| parent | d804473bbf326409856544200818279a9acda805 (diff) | |
remove and > and < , primitives, add and <= and >=, primitivesv.0.2.0
| -rw-r--r-- | README.md | 6 | ||||
| -rw-r--r-- | examples/mandelbrot.lali | 4 | ||||
| -rw-r--r-- | liblali.c | 23 |
3 files changed, 13 insertions, 20 deletions
@@ -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))))) @@ -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 }, }; |
