From 004f853f260d321753af32318ecdeb2c585af7b0 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 13 Mar 2024 15:22:05 +0100 Subject: Better string comparison using prefixed spaceship operator Co-authored-by: JoJoBarthold2 --- std/Number/Ternary.bruijn | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'std/Number/Ternary.bruijn') diff --git a/std/Number/Ternary.bruijn b/std/Number/Ternary.bruijn index 8cf891f..5e93c66 100644 --- a/std/Number/Ternary.bruijn +++ b/std/Number/Ternary.bruijn @@ -348,7 +348,7 @@ geq? \leq? ⧗ Number → Number → Boolean :test ((+2) ≥? (+2)) (true) :test ((+3) ≥? (+2)) (true) -# returns eq, lt, gt depending on comparison of two numbers +# returns eq, gt, lt depending on comparison of two numbers compare-case [[[[[go (1 - 0)]]]]] ⧗ a → b → c → Number → Number → d go [=?0 5 (>?0 4 3)] @@ -356,11 +356,22 @@ compare-case [[[[[go (1 - 0)]]]]] ⧗ a → b → c → Number → Number → d # also: spaceship operator compare compare-case (+0) (+1) (-1) ⧗ Number → Number → Number +…<=>… compare + +<=>‣ &compare + :test (compare (+2) (+2)) ((+0)) :test (compare (+2) (+1)) ((+1)) :test (compare (+1) (+2)) ((-1)) -…<=>… compare +# returns true if comparison result is equal (EQ) +c-eq? eq? (+0) ⧗ Number → Number + +# returns true if comparison result is less than (LT) +c-les? eq? (-1) ⧗ Number → Number + +# returns true if comparison result is greater than (GT) +c-gre? eq? (+1) ⧗ Number → Number # negates a balanced ternary number if <0 abs [