aboutsummaryrefslogtreecommitdiffstats
path: root/cppawk-cons.1
diff options
context:
space:
mode:
Diffstat (limited to 'cppawk-cons.1')
-rw-r--r--cppawk-cons.195
1 files changed, 83 insertions, 12 deletions
diff --git a/cppawk-cons.1 b/cppawk-cons.1
index 200876b..47bb0da 100644
--- a/cppawk-cons.1
+++ b/cppawk-cons.1
@@ -69,6 +69,7 @@ cons \- Lisp-like data representation and control flow macros
sexp(x) // convert Lisp value to S-expression string
equal(x, y) // test whether two Lisp values are equal
+ equalize(x) // convert object to canonical representation
list(...) // return argument values as a Lisp list
append(...) // append list arguments; last may be atom
@@ -888,12 +889,13 @@ function favors the last of these.
(nil . 1)
.ft R
-.SS Function \fIequal\fP
+.SS Functions \fIequal\fP and \fIequalize\fP
.bk
.B Syntax:
.ft B
equal(x, y)
+ equalize(x)
.ft R
.B Description
@@ -932,9 +934,9 @@ If
.I x
and
.I y
-are both numeric, then they are compared numerically, even if
-they are character strings. While this may seem to be the same as Awk equality,
-it is not the case. This rule is applied regardless of the origin of
+are both numbers, then they are compared numerically, While this may seem to be
+the same as Awk equality, that is not the case. This rule is applied regardless
+of the origin of
.I x
and
.IR y .
@@ -964,22 +966,26 @@ will print 1 when a record with the fields
.B 1
and
.B 1.0
-is processed. This is because at input time, Awk classifies such
-inputs as being numeric strings, attaching that to their type
-information, and two numeric strings are compared as numbers.
-Loosely speaking, the
+is processed. This is because Awk classifies certain inputs, such as fields
+delmited during input scanning, as being numeric strings if they look like
+numbers. This numeric string status is attached to their type information, and
+two numeric strings are compared as numbers. Yet, strings character-for-character
+identical to these which are produced via string manipulation are not treated
+as numeric. Loosely speaking, the
.B equal
-function compares two strings as numbers if they would be numeric
+function compares two (unboxed) strings as numbers if they would be numeric
strings if they were input as Awk fields.
.IP 2.
-A box string is
+A boxed string is
.B equal
-to an unboxed string of the same content, even though their Awk
-representation is different. In implementation terms:
+to an unboxed string of the same content, but only if the unboxed
+string isn't numeric. A numeric unboxed string is considered a number,
+and thus not equal to any boxed string.
.ft B
equal("Tabc", "abc") => 1
+ equal("T123", "123") => 0
.ft R
.IP 3.
@@ -1003,6 +1009,71 @@ to
.BI cdr( y )
.PP
+The
+.B equalize
+function is semantically related to
+.BR equal .
+It computes and returns an object similar to its argument object.
+If two objects
+.I x
+and
+.I y
+are considered to be the same by the
+.B equal
+function, then the expressions
+.BI equalize( x )
+and
+.BI equalize( y )
+each return the same string.
+
+That is to say, the following relationship holds between
+.B equalize
+and
+.BR equal :
+
+.ft B
+ equal(\fIx\fP, \fIy\fP) == (equalize(\fIx\fP) == equalize(\fIy\fP))
+.ft R
+
+Comparing two objects for equality using
+.B equal
+is the same as converting them to a canonical representation with
+.B equalize
+and then comparing that representation using the
+.B ==
+operator.
+
+The
+.b equalize
+function is useful for two reasons. Firstly, comparing objects with
+.B ==
+is much cheaper than
+.BR equal ;
+therefore, an application which performs a lot of comparisons
+may be made more efficient if it equalizes the objects and then
+uses the
+.B ==
+operator instead of
+.BR equal .
+
+Secondly, when equalized objects are used as keys for an Awk associative
+array, then, effectively, that array becomes based on
+.BR equal
+equality. That is to say, for instance, if the the objects
+.B "cons("1.0", "2.0")"
+and
+.B "cons(1, 2)"
+are used directly as associative array keys, they are different keys because
+their string representation is different. Yet, those two objects are
+.BN equal .
+Suppose that in some application there exists the requirement that
+.B equal
+objects must be be considered to be the same array key. This requirement
+can be satisfied by passing all keys through the
+.B equalize
+function, and using the equalized images of the keys for the
+array operations.
+
.SH "SEE ALSO"
cppawk(1)