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

Re: s/-LEFT//g?

This page is part of the web mail archives of SRFI 44 from before July 7th, 2015. The new archives for SRFI 44 contain all messages, not just those from before July 7th, 2015.

> On Thu, Oct 16, 2003 at 01:06:29PM -0700, Bradd W. Szonye wrote:
>> As an extension of my idea to change collection-fold-left to
>> collection-fold, how about removing all of the -lefts? Rationale:
>> 1. It's the naming convention in SRFI-1.
>> 2. The -left suffix doesn't make sense for "disordered" collections.
>> 3. It's less to type.

scgmille@xxxxxxxxxxxxxxxxxx wrote:
> Its less to type, but in this case its important, as it really is
> indicating directionality.  If it was just get-value or such, it
> wouldn't convey the message that its retrieving a very specific value
> from the collection, the left most or least precedent.

But that's only true for directional collections. Nondirectional
collections (like grab-bags and true mathematical sets) have no concept
of "first" or "last." In those cases, there is no message to convey,
because they necessarily return an arbitrary value, not a specific one.

> *-left provides a symmetry that the *-right functions can compare
> themselves against.  

While the names aren't symmetrical, there's just as much *conceptual*
symmetry in all of these:

    Convention                              Precedent
    *-method-left and *-method-right        PLT list.ss library
    *-method and *-method-right             SRFI-1
    *-method and *-reverse-method           C++ Standary Library

I would peronally prefer one of the latter two conventions, because
(1) *-method-left doesn't make sense for non-directional collections,
and (2) it's more to type.

I would also accept an alternate approach where all collections have
*-method and only directional collections have *-method-left and -right.

    Convention          Meaning
    *-method-left       operate from the left (least) end
    *-method-right      operate from the right (greatest) end
    *-method            operate in arbitrary order

Directional (aka "reversible") collections would probably define
*-method to be equivalent to *-method-left, but that shouldn't be a
requirement. This way, you could implement an ordered-hash-table which
would provide these enumerators:

    collection-fold         enumerate in efficient (storage) order
    collection-fold-left    enumerate in sorted order
    collection-fold-right   enumerate in reverse-sorted order

In general, I would expect a directional collection to use *-method for
the most efficient order, *-method-left for guaranteed in-order, and
*-method-right for guaranteed reverse-order. For many directional
collections, but not all of them, *-method and *-method-left will be the

I like this approach because it allows totally generic algorithms (i.e.,
algorithms that don't care whether it's an ordered collection) to use
the most efficient methods -- you only get the (possibly-inefficient)
in-order methods when you specifically ask for them.

I think this would resolve both my objections and yours:

1. No more applying "directional" method names like *-left to
   non-directional collections.
2. Directional/reversible collections have symmetric method names.
3. Less verbose naming convention for common cases.

Plus an added benefit:

4. Directional collections have (possibly more efficient) nondirectional
   methods for users who don't care about the order of elements.


All containers have *-method, which uses an arbitrary order.

Reversible containers have *-method-left and *-method-right, which use
the container's ordering-function or inherent order (for sequences).

Reversible containers may optionally define *-method to use a specific
ordering (usually "same as *-method-left"  or "most efficient order").
Bradd W. Szonye