[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: About hash-table iterators
From: |
Mikael Djurfeldt |
Subject: |
Re: About hash-table iterators |
Date: |
Tue, 27 Jan 2004 11:07:53 -0500 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
[Cross-posting to guile-devel]
Roland Orre <address@hidden> writes:
> The elements of a hash table I consider the handles, not the key and
> the value as separate entities, therefore I don't consider the current
> iterators hash-map and hash-for-each in guile 1.7 very useful and the
> basic iterators I've used over the year, i.e iterating over the handles,
> can not be constructed from them. To be able to implement my previous
> functionality I had to copy and modify a few routines from hashtab.c to
> be able to implement e.g
>
> hash-for-each-handle
> hash-map-handles
> and from the latter can then e.g hash-table->list be implemented
>
> (define-public (hash-table->list htable) (hash-map-handles id htable))
>
> and when you don't want to be able to modify the original table you can
> use hash-map instead:
> (define-public (hash-table-copy->list htable) (hash-map cons htable))
>
> Is this a general interest? In that case these maybe they should be
> considered the basic iterators provided instead of hash-for-each and
> hash-map as the latter can be implemented from the other but not vice
> versa?
The design decision for hash-for-each and hash-map was to abstract
away the handle's, which are lower-level details of the representation
of the table, and, also, to promote a functional style of programming.
The decision is supported by the same choice made for Common Lisps's
`maphash' (although Common Lisp has setf so that the side-effects (the
*only* effects, btw) also include mutating the table). Also, java
does not use the concept of handles either.
However, we *do* support handles in another set of functions.
(Unfortunately, the abstraction is not complete here. If we pass out
a handle object, we should have accessor and mutator functions for
this object and not just presume that it is a pair!)
So, I'm inclined to support your idea of introducing
hash-for-each-handle.
I don't think we need to introduce hash-map-handles, though.
Also: Is it the case that hash-map has a really bad name? It strikes
me that one would expect hash-map to return another hash table.
Should it instead be named hash-map-to-list or something better?
M
- Re: About hash-table iterators,
Mikael Djurfeldt <=