Why do two different implementations of pairs (mutable and immutable) have
two different interfaces?

I suggest that immutable pairs should use the same names (cons, car, cdr,
pair?, etc) as mutable pairs. A programmer can control which implementation
of pairs they use in a particular module using import.

The only downsides that I can see are (1) a programmer who uses both
implementations of pairs will have to do more work and (2) because (scheme
base) contains a bunch of stuff in addition to mutable pairs, using it with
immutable pairs would require something like (import (except (scheme base)
cons car cdr pair? ...)).

Issue (2) could be solved by factoring (scheme base) into pieces: (scheme
base pairs), (scheme base strings), etc.


On Sun, Aug 31, 2014 at 7:50 PM, John Cowan <co...@mercury.ccil.org> wrote:

> Note: The SRFI number is not yet official and is therefore subject to
> change.
>
> Abstract:
>
> Scheme currently does not provide immutable pairs corresponding to its
> existing mutable pairs, although most uses of pairs do not exploit
> their mutability. The Racket system takes the radical approach of
> making Scheme's pairs immutable, and providing a minimal library of
> mutable pairs with procedures named mpair?, mcons, mcar, mcdr, set-mcar!,
> set-mcdr!. This SRFI takes the opposite approach of leaving Scheme's pairs
> unchanged and providing a full set of routines for creating and dealing
> with immutable pairs. The sample implementation is portable and efficient.
>
> Rationale:
>
> Rather than attempting to design this library from scratch, I have chosen
> the conservative option of modifying SRFI 1. Consequently, most of the
> rationale given in that document applies to this one as well. I have
> made the following changes:
>
> * Removed all linear-update procedures ending in !
>
> * Removed all references to circular lists (there will be a future SRFI for
>   immutable bidirectional cycles).
>
> * Removed first, second , etc., which are mostly used for poor man's
> records.
>
> * Removed the O(n2) lists-as-sets procedures (there will be a future SRFI
>   supporting O(n log n) immutable sets).
>
> * Inserted an i at a judicious place in each identifier, usually at the
>   beginning. However, because "icons" means something else in both ordinary
>   English and computer jargon, the basic constructor and its immediate
>   relatives are named ipair, xipair and ipair* instead.
>
> * Added procedures for conversion between ordinary and immutable pairs,
> lists,
>   and trees.
>
> * Added an analogue of apply for applying a procedure to an immutable list
> of
>   arguments.
>
> SRFI:  http://www.ccil.org/~cowan/temp/srfi-116.html
> Implementation:  http://www.ccil.org/~cowan/temp/ilists.tar.gz
>
> Please send comments to <srfi-...@srfi.schemers.org> when it is created,
> or to this list in the meantime.
>
> --
> John Cowan          http://www.ccil.org/~cowan        co...@ccil.org
> Schlingt dreifach einen Kreis vom dies!
> Schliesst euer Aug vor heiliger Schau,
> Denn er genoss vom Honig-Tau,
> Und trank die Milch vom Paradies.
>
> _______________________________________________
> Scheme-reports mailing list
> Scheme-reports@scheme-reports.org
> http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports
>
_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports

Reply via email to