5 ms·
>commonly-needed things as, say, hashes Hash tables are commonly used in imperative programming, but they aren't needed so often in Scheme where we prefer to u
by davexunit 12y ago
>commonly-needed things as, say, hashes
Hash tables are commonly used in imperative programming, but they aren't needed so often in Scheme where we prefer to use a purely functional style. We usually use alists because they are persistent. When I reach for a mutable hash table, it's usually part of some imperative process where I start from an empty table.
Depending on the Scheme you use, there could also be a persistent hash table implementation. Guile has vhashes, and there's an alist->vhash procedure, so you can still use the alist syntax.
- technomancy 12y agoHash tables have nothing to do with imperative programming. It's just a coincidence that some MLs or Schemes don't include purely functional hash tables; Clojure and Racket both include have them.
- davexunit 12y agoI mentioned that Guile also has one, called a vhash. I guess my point is that special read syntax for them isn't that useful when you can use an alist and convert.
- technomancy 12y agoSounds like a bit of a turing tarpit if you ask me. Sure there are technically ways to work around the lack of read syntax (I mean, Java didn't have literal syntax for any non-array collections for ages) but that doesn't mean it's a good idea.
- innguest 12y agoThis is wrong. There are no purely functional data structures analogous to hash tables in terms of performance. Hash tables are inherently stateful and cannot be implemented without state.
- technomancy 12y agoMost people are OK taking a small performance hit for the simplicity of working with immutable data.