[plt-scheme] Convention for alists?
It's not really a convention -- the two examples specify two different types
of tables. The first maps symbols to numbers while the second maps symbols
to lists of numbers. An entry of the of the first sort of alist might be
updated by replacing the value with another number, whereas an entry of the
second sort of alist might be updated by consing another number to the
value. Think of an alist recording counts of letters in a string versus an
alist recording the locations of those letters. I've had occasion to use
both.
-- Bill Wood
bill.wood at acm.org
----- Original Message -----
From: "Doug Orleans" <dougo at place.org>
To: "Richard Cobbe" <cobbe at ccs.neu.edu>
Cc: "PLT Scheme List" <plt-scheme at list.cs.brown.edu>
Sent: Saturday, April 02, 2005 9:16 PM
Subject: Re: [plt-scheme] Convention for alists?
> 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?)
>
> I tend to prefer the first, and SRFI-1's `alist-cons' seems to
> encourage it also. 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).
>
> --dougo at place.org
>