[plt-scheme] Convention for alists?

From: John Clements (clements at brinckerhoff.org)
Date: Sun Apr 3 17:31:37 EDT 2005

On Apr 3, 2005, at 10:54 AM, Richard Cobbe wrote:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> 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.

While I share your distaste for dotted pairs, and tend to code 
a-maps-to-6 as '(a 6) in my own code, another un-mentioned advantage of 
the dotted one is that there's one less invariant to maintain:  that 
is, if you represent a-maps-to-list-containing-4-and-5 as '(a (4 5)), 
then what the heck does (a 4 5) represent?  It's not well-formed data.  
The dotted pair representation doesn't make that particular error 
possible.

Apologies if this was just so obvious you didn't mention it.

john



Posted on the users mailing list.