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

building other EQUIV?-like predicates




Will,

Good thing! Fills a long standing gap in Scheme,
and whenever I actually needed EQUIV? there was
no time to implement it reliably (so I always
ended up with a hack for the specific situation).

There is one thing I was asking myself when I
saw the SRFI:

In many cases I need an application-specific
equivalence which is not among the predefined
ones. For example, it should deal with cyclic
structures the way EQUIV? does, but floats are
compared only up to a certain tolerance (not
that this results in an actual 'equivalence,'
but it is often needed as a predicate anyhow).
Another example is the presence of user-defined
record types; equivalence predicates that are
meaningful for the application can ignore some
fields while recursing only on others.

In these situations, I would still end up implementing a
lot of code similar to the reference implementation you
give but with little modifications in the recursion, or
for the atomic types.

So I asked myself if it would be feasible to make
a 'toolkit' for defining recursive equivalence
relations. Without having thought thoroughly about
this, I think the toolkit can take the form of a single macro,
say SELECT-EQUIV?.

In SRFI 67 (compare procedures) there is a macro
SELECT-COMPARE which makes it a convenient thing
to define a (partially) recursive comparison procedure:

    http://srfi.schemers.org/srfi-67/srfi-67.html#node_toc_node_sec_4.5

An example is DEFAULT-COMPARE:

    http://srfi.schemers.org/srfi-67/srfi-67.html#node_toc_node_sec_4.4

For SRFI 67 we did not want to go into cyclic structures at all,
mainly because the SRFI was already becoming too complex
for its overall purpose.

So my concrete question/proposal:

Do you think a 'SELECT-EQUIV?' macro would make
sense which dispatches on the types of its two arguments
to control recursion, but can handle cyclic structures by
maintaining a stack of subtasks?

Sebastian.