This is the mail archive of the
kawa@sourceware.cygnus.com
mailing list for the Kawa project.
Association lists
- To: kawa at sourceware dot cygnus dot com
- Subject: Association lists
- From: "Nic Ferrier" <nferrier at tapsellferrier dot co dot uk>
- Date: Thu, 22 Jun 2000 18:04:33 +0100
Scheme supports hash operations on lists to allows lists to be treated
as hash tables.
I was wondering: do most Scheme implementations optimize lists that
are used as hashes into real hashes?
If so is that something that Kawa could do?
I guess it's either quite a lot of lexical analysis from the
compilers view-point (to ensure that a hash never becomes a list) or
it's a clever but heavy implementation of a list.
A clever but heavy implementation of a list that could do native
hashing sounds to me like it might work like this:
- operations on elements of the list must be able to delegate to a
central point
(so that the list can know when it is a hash)
- a list must be able to keep references to the car and cdr of pairs
contained within the list in an internal hashmap
- the list implementation would have to *implement* the java.util.Map
interface
(so Java could treat it as a hash)
- the Map implementation would have to communicate with the the list
implementation to ensure the list structure remained.
- the assoc-list implementation would have to use the native Map
interface.
The reason I ask is that my SAXish processor needs to pass a hash of
element attributes to a Java method. The Scheme code generates the
hash and I've used generalized assoc-list stuff.
I can of course make a hashmap using Scheme but then I have to call
it with lots of method invocation - not as nice as just Scheme.
I am also working on a browser component that will use Kawa instead
of JS (in the hope that I'll be able to eventually get Kawa to provide
ECMAscript) and as a lot of browser scripting involves playing with
hashes of attributes it would be nice if the interface were more
scheme than Java (otherwise I might as well make the script engine
JS).
Nic