Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Testing instances for equality

32 views
Skip to first unread message

Udyant Wig

unread,
Jan 2, 2019, 1:21:57 AM1/2/19
to
I have some working code using structures for which I have written tests
with the old RT package. The predicate I have pressed into service is
EQUALP, as it descends into structures while examining them for
equality.

I was hoping to explore an alternative class-based design, but I ran
aground thinking about which predicate to use.

Am I missing something fundamental about CLOS? Would I be best served
writing my own predicates for instances per se, and instances in lists?

Udyant Wig
--
We make our discoveries through our mistakes: we watch one another's
success: and where there is freedom to experiment there is hope to
improve.
-- Arthur Quiller-Couch

Pascal J. Bourguignon

unread,
Jan 2, 2019, 5:16:29 AM1/2/19
to
Udyant Wig <udy...@gmail.com> writes:

> I have some working code using structures for which I have written tests
> with the old RT package. The predicate I have pressed into service is
> EQUALP, as it descends into structures while examining them for
> equality.
>
> I was hoping to explore an alternative class-based design, but I ran
> aground thinking about which predicate to use.
>
> Am I missing something fundamental about CLOS? Would I be best served
> writing my own predicates for instances per se, and instances in lists?


equalp is nice, but you must remember that it compares strings
case-insensitively.

(defstruct person name)
(equalp (make-person :name "foo") (make-person :name "Foo")) -> t

So, yes, defining your own method is not a bad idea.
Using a common generic function may be indicated, or not.
Have a look at CDR-8
https://common-lisp.net/project/cdr/document/8/index.html

--
__Pascal Bourguignon__

Rob Warnock

unread,
Jan 2, 2019, 9:30:15 AM1/2/19
to
Pascal J. Bourguignon <p...@informatimago.com> wrote:
+---------------
| Udyant Wig <udy...@gmail.com> writes:
| > I have some working code using structures for which I have written tests
| > with the old RT package. The predicate I have pressed into service is
| > EQUALP, as it descends into structures while examining them for equality.
...
| equalp is nice, but you must remember that it compares strings
| case-insensitively.
...
| So, yes, defining your own method is not a bad idea.
| Using a common generic function may be indicated, or not.
| Have a look at CDR-8
| https://common-lisp.net/project/cdr/document/8/index.html
+---------------

The OP might also find it helpful to read Kent Pitman's classic essay
on COPY & EQUALITY -- despite its age (circa 1993) -- in which he
shows just how difficult it is to get generic equality testing right:

http://www.nhplace.com/kent/PS/EQUAL.html
The Best of Intentions
EQUAL Rights--and Wrongs--in Lisp


-Rob

-----
Rob Warnock <rp...@rpw3.org>
627 26th Avenue <http://rpw3.org/>
San Mateo, CA 94403

Udyant Wig

unread,
Jan 3, 2019, 12:17:08 AM1/3/19
to
On 1/2/19 8:00 PM, Rob Warnock wrote:
> The OP might also find it helpful to read Kent Pitman's classic essay
> on COPY & EQUALITY -- despite its age (circa 1993) -- in which he
> shows just how difficult it is to get generic equality testing right:
>
> http://www.nhplace.com/kent/PS/EQUAL.html
> The Best of Intentions
> EQUAL Rights--and Wrongs--in Lisp

Thank you for the link to a very fascinating paper. It argues the point
convincingly.

> -Rob

Udyant Wig

unread,
Jan 3, 2019, 12:30:13 AM1/3/19
to
On 1/2/19 3:46 PM, Pascal J. Bourguignon wrote:
> equalp is nice, but you must remember that it compares strings
> case-insensitively.
>
> (defstruct person name)
> (equalp (make-person :name "foo") (make-person :name "Foo")) -> t

Indeed. In my code, the structures do not house strings, so I had
decided to go along with EQUALP.

Part of my motivation to use structures was that CMUCL documentation
states that the Python compiler deals well with them.

> So, yes, defining your own method is not a bad idea.
> Using a common generic function may be indicated, or not.
> Have a look at CDR-8
> https://common-lisp.net/project/cdr/document/8/index.html

This proposal looks good. Is there an implementation of it somewhere?

Marco Antoniotti

unread,
Jan 6, 2019, 3:26:46 AM1/6/19
to
On 2019-01-03 05:46:59 +0000, Udyant Wig said:

> On 1/2/19 8:00 PM, Rob Warnock wrote:
>> The OP might also find it helpful to read Kent Pitman's classic essay
>> on COPY & EQUALITY -- despite its age (circa 1993) -- in which he
>> shows just how difficult it is to get generic equality testing right:
>>
>> http://www.nhplace.com/kent/PS/EQUAL.html
>> The Best of Intentions
>> EQUAL Rights--and Wrongs--in Lisp
>
> Thank you for the link to a very fascinating paper. It argues the point
> convincingly.


You may also want to check CDR 8.

https://common-lisp.net/project/cdr/document/8/index.html

Cheers
--
MA

0 new messages