Re: [Scheme-reports] Legacy caar to cddddr Aubrey Jaffer (23 Oct 2011 22:50 UTC)
Re: [Scheme-reports] Legacy caar to cddddr Alex Shinn (24 Oct 2011 14:09 UTC)
Re: [Scheme-reports] Legacy caar to cddddr Aubrey Jaffer (24 Oct 2011 16:02 UTC)
Re: [Scheme-reports] Legacy caar to cddddr John Cowan (24 Oct 2011 21:17 UTC)
Re: [Scheme-reports] Legacy caar to cddddr Alex Shinn (24 Oct 2011 23:58 UTC)
Re: [Scheme-reports] Legacy caar to cddddr Andre van Tonder (24 Oct 2011 16:04 UTC)
Re: [Scheme-reports] Legacy caar to cddddr Alaric Snell-Pym (24 Oct 2011 16:09 UTC)
Re: [Scheme-reports] Legacy caar to cddddr Alex Shinn (25 Oct 2011 00:07 UTC)
Re: [Scheme-reports] Legacy caar to cddddr John Cowan (24 Oct 2011 17:02 UTC)
Re: [Scheme-reports] Legacy caar to cddddr Ray Dillinger (24 Oct 2011 21:30 UTC)
Re: [Scheme-reports] Legacy caar to cddddr John Cowan (24 Oct 2011 21:51 UTC)

Re: [Scheme-reports] Legacy caar to cddddr Alex Shinn 25 Oct 2011 00:06 UTC

On Tue, Oct 25, 2011 at 1:03 AM, Andre van Tonder <andre@het.brown.edu> wrote:
> On Mon, 24 Oct 2011, Alex Shinn wrote:
>
>> I'd be interested to see real-world examples of (set-car! (c[ad]{3,}r x)
>> y).
>> My guess is these are examples of abusing lists as records.
>
> Whether to call this an abuse is very subjective, depending very much on the
> type system you are imposing in your mind on your Scheme program.

Types are one concern, time and space efficiency another.
Once you get past three fields vectors are smaller, and should
be faster in any optimizing compiler.

> As for which composite selectors should be provided by default, I agree with
> yout that one can probably suppress some of the selectors deeper than the
> spine of the list.  But maybe one could expand the number of selectors along
> the spine itself.  I have often run into the following:
>
>    (define binding-type           car)
>    (define binding-name           cadr)
>    (define binding-levels         caddr)
>    (define binding-mutable?       cadddr)
>    (define (binding-dimension b)  (car (cddddr b))) ; UGLY
>
> The last line is not a tragedy, but it is ugly.  Also, some optimizing
> implementations might be able to provide random access to more than 4
> initial elements of short lists.

SRFI-1 already extends the spine to `tenth', though
you may choose to rename the binding on import.
However, whatever depth you have, somewhere you'll
always have that ugly case unless you use more
general accessors like list-ref.

But more importantly, those definitions should only
ever occur once so the actual implementation is
abstract and the ugliness is minimized.

--
Alex

_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports