[r6rs-discuss] [Formal] Rationalize Iteration
Anton van Straaten
anton at appsolutions.com
Sat Nov 11 02:49:03 EST 2006
MichaelL at frogware.com wrote:
> * Why is folding the only iteration offered for hash tables?
> Chez Scheme and PLT Scheme both offer hash table map and "each"
> procedures. Though they could both be written in terms of hash-table-fold,
> R6RS follows a funny line, dramatically expanding the number of list
> utilities while at the same time keeping a minimal set of operations for
> other types--more or less.
> * If the philosophy is to provide a reasonable set, some thought should
> be given to what that set should be, and that set should be implemented
> for all types where it makes sense. A reasonable set might be fold with
> premature termination, fold without premature termination (for
> convenience), map, and for-each.
Just an informal & narrow reply specifically about hash table map:
The map operation has an obvious, useful specification for lists and
vectors: the former maps lists to lists, and the latter maps vectors to
vectors. One might reasonably extend this to hash tables and specify
that a hash table map function should return a hash table. This is what
SML/NJ does, for example.
However, I'm not aware of any Scheme which does this. According to SRFI
69, "In no implementation that I know of, hash-table-map does a real
functorial map that lifts an ordinary function to the domain of hash
tables." SRFI 69 omits hash table map for this reason. Some Scheme
implementations, such as Gambit and Chicken, implement hash tables but
don't provide a map function for them. Similarly, hash table libraries
for some other languages, such as OCaml and Haskell, also omit map.
A number of other Scheme implementations, including Chez, PLT, Larceny,
and Gauche, provide a hash table map function which returns a list,
rather than a hash table. This seems to indicate that a hash table map
which returns a hash table is not considered particularly necessary in
practice, which argues against specifying such a function in R6RS.
Ignoring a multitude of options that I haven't mentioned above, this
leaves the following question: assume the editors decide, belatedly,
that the R6RS philosophy should be "to provide a reasonable set [...]
and that set should be implemented for all types where it makes sense",
does it make sense for R6RS to specify a hash table map function which
returns a list?
BTW, I don't consider any of this to affect the overall point of the
original formal comment.
More information about the r6rs-discuss