diff man/lispref/objects.texi @ 4792:95b04754ea8c

Make #'equalp more compatible with CL; add a compiler macro, test & doc it. lisp/ChangeLog addition: 2009-11-08 Aidan Kehoe <kehoea@parhasard.net> * cl-extra.el (cl-string-vector-equalp) (cl-bit-vector-vector-equalp, cl-vector-array-equalp) (cl-hash-table-contents-equalp): New functions, to implement equalp treating arrays with identical contents as equivalent, as specified by Common Lisp. (equalp): Revise this function to implement array equivalence, and the hash-table equalp behaviour specified by CL. * cl-macs.el (equalp): Add a compiler macro for this function, used when one of the arguments is constant, and as such, its type is known at compile time. man/ChangeLog addition: 2009-11-08 Aidan Kehoe <kehoea@parhasard.net> * lispref/objects.texi (Equality Predicates): Document #'equalp here, as well as #'equal and #'eq. tests/ChangeLog addition: 2009-12-31 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-tests.el: Test much of the functionality of equalp; add a pointer to Paul Dietz' ANSI test suite for this function, converted to Emacs Lisp. Not including the tests themselves in XEmacs because who owns the copyright on the files is unclear and the GCL people didn't respond to my queries.
author Aidan Kehoe <kehoea@parhasard.net>
date Thu, 31 Dec 2009 15:09:41 +0000
parents f9104f0e9b91
children e6dec75ded0e
line wrap: on
line diff
--- a/man/lispref/objects.texi	Thu Dec 31 08:21:30 2009 +0000
+++ b/man/lispref/objects.texi	Thu Dec 31 15:09:41 2009 +0000
@@ -2424,3 +2424,56 @@
 
   The test for equality is implemented recursively, and circular lists may
 therefore cause infinite recursion (leading to an error).
+
+@defun equalp object1 object2
+This function is like @code{equal}, but compares characters and strings
+case-insensitively; numbers are compared using @code{=}; arrays (that
+is, strings, bit-vectors and vectors) are regarded as being
+@code{equalp} if their contents are @code{equalp}; and
+@code{hash-tables} are @code{equalp} if their values are @code{equalp}
+and they would otherwise be @code{equal}.
+
+@code{equalp} is recursive with vectors, lists and hash-tables, but not
+with other complex types.  For types without a defined @code{equalp}
+behavior, @code{equalp} behaves as @code{equal} does. 
+
+@example
+@group
+(equalp "asdf" "ASDF")
+     @result{} t
+@end group
+@group
+(equalp "asdf" [?a ?s ?D ?F])
+     @result{} t
+@end group
+@group
+(equalp "asdf" [?a ?s ?D ?F ?g])
+     @result{} nil
+@end group
+@group
+(equalp "" (bit-vector))
+     @result{} t
+@end group
+@group
+(equalp #s(hash-table) (make-hash-table))
+     @result{} t
+@end group
+@group
+(equalp #s(hash-table data (t "hi there"))
+	(let ((ht (make-hash-table)))
+	  (puthash t "HI THERE" ht)
+	  ht))
+     @result{} t
+@group
+@end group
+(equalp #s(hash-table test eq data (1.0 "hi there"))
+	(let ((ht (make-hash-table :test 'eql)))
+	  (puthash 1.0 "HI THERE" ht)
+	  ht))
+     @result{} nil
+@end group
+@end example
+@end defun
+
+@code{equalp} can also provoke an error if handed a circular structure,
+as with @code{equal}.