[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Are isomorphic structures EQUAL?



    Date: 11 Apr 1986 16:43-EST
    From: NGALL@G.BBN.COM

    I don't want to reopen the discussion that we had about equality a
    while back, but someone in my group just tripped over an ambiguity in
    the manual.

    She was using DEFSTRUCT with the (:TYPE ...) option and using EQUAL to
    compare structures and everything worked fine since EQUAL did a
    component-wise equality test.

    Then she got bold and decided to let DEFSTRUCT choose the
    representation, so she left off the (:TYPE ...) option.  Low and
    behold, EQUAL did not do a component-wise equality test, it tested for
    EQL!

    So she looked at the def. on page 80 where it said "Certain objects
    that have components are EQUAL if they are of the same type and
    corresponding components are EQUAL."  Unfortunately, the rest of the
    definition did not make it at all clear whether or not objects created
    by DEFSTRUCT were among these "Certain objects".  Looking on the next
    page at the def. of EQUALP (which happened to do a component-wise
    equality test), she read "Objects that have components..."  The only
    difference was the word "Certain"!

    So we tried it on another CL (SymbolicsCL), and got the same behavior
    (as with VaxLisp).  Which leads me to almost believe that EQUAL NOT
    supposed to to a component-wise test for equality.  Except...

    What happens to implementations that want to represent structures
    using plain old vectors?  How will EQUAL distinguish vectors from
    structure-vectors?

As Rees pointed out, such an implementation would not be legal.

    This interaction of DEFSTRUCT/EQUAL is going to cause a lot of bugs.
    People are going to prototype structues using the (:TYPE LIST) option
    and use EQUAL to do equality tests.  Then when they remove the :TYPE
    option, KaBoom!

I don't think that's a plausible way to program, but I agree that "equality"
is an area of the language that needs work.

    There will be no way to do a component-wise test (using EQUAL on each
    component) on two structures unless one writes a structure-specific
    equality predicate.

    Therefore, I propose that two structures of the same type that are
    created by DEFSTRUCT (regardless of the :TYPE option) be tested for
    equality component-wise and that the CLtL make this clear.

    Until then, she can get by with EQUALP (since her structures don't
    conatin strings, floats, etc.).

I don't understand this.  I can't find anything in the manual that says
that EQUALP behaves differently than EQUAL for structures.  Actually I
can't find anything in the manual that says anything at all about the
behavior of either EQUAL or EQUALP on structures.

It may be that by coincidence the two implementations you mentioned in
your message both compare components of structures (with the default
defstruct options, especially no :TYPE) in EQUALP, and do not compare
components of structures in EQUAL, but I don't think the Common Lisp
manual says that all implementations have to do that.