This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Scheme is too complicated


Ian Bicking <ian@bickiia.earlhall.earlham.edu> writes:

> I don't see any actual reason for association lists except
> compatability.  A hash-table should mimic all the association list
> behavior.  Unfortunately, if you make sequence functions act like (1)
> you won't get this alist like behavior, you'll need seperate functions 
> that act on the associations.  Not a big deal, but then hash-tables
> wouldn't be drop-in replacements for alists.

I see one reason for association lists, for some applications.  Alists
are "persistent"; if you modify an alist by sticking new pairs on the
front (instead of by mutating internal cons cells), then other
references to the alist are not modified.

This sort of behavior is useful in the symbol table of a compiler, for
instance.  When you leave a scope, you want to return the symbol table
to the state it was in before you entered the scope; this is trivial
with an alist, but would typically be fairly complicated if the symbol
table were a hash table.

Of course, this isn't a great example, because in a real compiler, the
inefficiency of an alist is usually unacceptable.  Regardless,
persistent data structures are useful; see Chris Okasaki's _Purely
Functional Data Structures_ for more on this subject.

Carl Witty
cwitty@newtonlabs.com