Re: [CLOS] Ensuring a method exists



Rahul Jain wrote:
Pascal Costanza <pc@xxxxxxxxx> writes:

Rahul Jain wrote:
Equality is not an OO concept. You should not be using a g-f to
determine equality.
Says who?

Says me. ;)

;)

But seriously. Equality is not just inherited. Note that I qualified my
use of OO below. It's fine to compare objects, just not in a way that
gets inherited by subclasses.

What would it mean for me to compare a point to a
color-point? And I mean OO in the polymorphic sense, not the
encapsulation sense.
Comparing a point to a color-point could have different meanings
depending on context. I can imagine situations in which a default color
is assumed for non-color points. I can also imagine situations in which
the color is simply ignored. Even throwing a dedicated exception can be
a well-defined behavior, especially with the condition handling system
in CL.

Right, I tried to make that point before when I described what _I_ would
expect a point= function to do. Of course, all such discussions are
mental masturbation because what really matters is what a specific
application wants to compare. But I don't see how that implies that g-fs
are the way to implement such (a) function(s). In fact, I would think
that it would indicate that g-fs are the wrong way to do it because it
implies that such operators can be arbitrarily augmented by other
libraries. This may not result in expected behavior in all applications.

I think generic functions can be appropriate, but I agree with you that they are probably not sufficient the way they are.

I said "depending on context" for a reason: I think something like dynamically scoped functions or ContextL can be of use here. For example, the different cases could be captured in different ContextL-layers and then selected appropriately.

I haven't tried this yet for comparison functions, so take this with a grain of salt.

But if it turns out that it could work like that, that would actually be an acknowledgment of Christophe's position as well. OOP may not be appropriate for such tasks yet, but this could be because we still don't have OOP systems that are general enough. (That's not what he said, but that's roughly how I understand him. And it resonates with my point of view... ;)

There's a reason why the equality operators in CL are not g-fs.
The equality operators in CL are generic in the sense that they are
applicable for several types. You just can't define methods on them (and
even that is not a given, since the CL spec allows implementations to
provide all plain functions as CLOS generic functions).

Right. I don't like equal or equalp for that exact reason. They're just
a mishmash of other equality operators on specific types. There's no
reason that specific combination should be preferred over any other. I
consider them to be historical artifacts.

OK, that's indeed arguable.


Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
.



Relevant Pages

  • Re: [CLOS] Ensuring a method exists
    ... Equality is not just inherited. ... application wants to compare. ... The equality operators in CL are generic in the sense that they are ... I don't like equal or equalp for that exact reason. ...
    (comp.lang.lisp)
  • Re: Geese vs ganders (was most climbed with rec.climber)
    ... Context and circumstances may rebut or, ... You yourself used the words "nominal equality". ... the Supreme Court in Brown v. ... We're "getting over" Affirmative Action. ...
    (rec.climbing)
  • Re: collection framework: using the good interface
    ... The word object's class would implement Comparable, and should have equals and hashCode consistent with compareTo, but I would not make two words equal unless they are, in all respects, the same word. ... I'm more and more convinced that equality should involve all aspects of the Word class, but I'm still uncomfortable with mixing lexicographic information (allowing to compare objects in different collections) and information about frequency, distribution, cooccurrents. ...
    (comp.lang.java.help)
  • Re: If statement
    ... i want to compare atabsin equality ... or call the function atabs passing in the argument i ... since that value is *not* non-zero, ...
    (comp.soft-sys.matlab)
  • Re: Database design
    ... is interestingly to compare them. ... and some here insisting that one framework ... Flat in the context of a heirarchy. ...
    (comp.databases.theory)