[plt-scheme] Convention for alists?

From: Richard Cobbe (cobbe at ccs.neu.edu)
Date: Sun Apr 3 10:54:50 EDT 2005

On Sat, Apr 02, 2005 at 10:16:23PM -0500, Doug Orleans wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> Richard Cobbe writes:
>  > Is there a commonly-accepted convention for the shape of an association
>  > list?  I've seen both
>  >     '((a . 3) (b . 4) (c . 5))
>  > and
>  >     '((a 3) (b 4) (c 5))
>  > before.
>  > 
>  > Clearly, the R5RS primitives will work on both, as will assf from
>  > etc.ss; it's just a question of how one extracts the values.
>  > 
>  > (Here's the context: my environment library, in PLaneT/300, exports an
>  > env->alist function that returns a list of the second form above.
>  > Should I change it to the first?)

The only reason I've used the second form is a mild distaste on my part
for dotted pairs, but in the absence of a clear convention, I don't have
a very strong preference one way or the other.

> I tend to prefer the first, and SRFI-1's `alist-cons' seems to
> encourage it also.

Ok, SRFI-1 is a point in favor of the dotted-pair representation.
Thanks for pointing that out.

> I think the second form is mainly used for literal alists, because the
> representation is shorter, but of course the former uses less memory
> (or no more memory-- I guess in a cdr-coded implementation they'd be
> the same).

True.  The main reason I included the env->alist function (and the
primary thing I've used it for) is to render the environment into a form
that's easily printed and compared with equal?, for testing and
debugging reasons.  So readability is (for me, at least) a primary
concern.

Richard



Posted on the users mailing list.