From 9c51abd7297034b9b109eafcf01021fbd2876ba4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 5 Apr 2022 21:31:39 -0700 Subject: New function equalize. --- cppawk-include/cons-priv.h | 30 ++++++++++++++++++++++++++---- cppawk-include/cons.h | 1 + 2 files changed, 27 insertions(+), 4 deletions(-) (limited to 'cppawk-include') diff --git a/cppawk-include/cons-priv.h b/cppawk-include/cons-priv.h index 8a57215..3ce5873 100644 --- a/cppawk-include/cons-priv.h +++ b/cppawk-include/cons-priv.h @@ -216,6 +216,7 @@ function __box_str(__str) { return "T" __str } +#define __box_str(str) ("T" (str)) function __box_sym(__name) { @@ -382,16 +383,37 @@ function __slow_equal(__obj1, __obj2, } if (__tc1 == "T") - return __unbox(__obj1) == __obj2; + return __numberp(__obj2) ? 0 : (__obj1 == __box_str(__obj2)) if (__tc2 == "T") - return __obj1 == __unbox(__obj2); + return __numberp(__obj1) ? 0 : (__box_str(__obj1) == __obj2) - if (__numberp(__obj1) && __numberp(__obj2)) { + if (__numberp(__obj1) && __numberp(__obj2)) return __obj1 + 0 == __obj2 + 0 + + return 0 +} + +function __equalize(__obj, + __tc, __str) +{ + if (!__present(__obj)) + return "" + + __tc = __typecode(__obj) + + __case (__tc) { + __of("C") + __cret (__cons(__equalize(__car(__obj)), + __equalize(__cdr(__obj)))) + __of("T", "S", "U", "") + __cret (__obj) } - return 0; + if (__numberp(__obj)) + return __obj + 0 + + return __box_str(__obj) } function __pack(__stk, __item) diff --git a/cppawk-include/cons.h b/cppawk-include/cons.h index 560784a..0087930 100644 --- a/cppawk-include/cons.h +++ b/cppawk-include/cons.h @@ -69,6 +69,7 @@ #define ltof __ltof #define keys __keys #define equal __equal +#define equalize __equalize #define list __list #define li __li #define listar __listar -- cgit v1.2.3