4 ms·
The one thing that keeps me away from Lisp/Scheme is the lack of built-in syntax for hashmaps and sets (I like Clojure's syntax, but don't want the JVM). I've
by basketcasing 11y ago
The one thing that keeps me away from Lisp/Scheme is the lack of built-in syntax for hashmaps and sets (I like Clojure's syntax, but don't want the JVM).
I've never gotten the hang of car/cdr and dotted pairs.
- davexunit 11y agoI don't think this is a particularly large problem. Traditional hash tables are imperative data structures, and Lisp code (or Scheme code, at least) typically does not use them because of this. Association lists, which can be represented as literals, are persistent and provider faster lookup, despite being O(n), for the cases in which hash literals are typically used (small number of pairs). The Clojure language has built-in persistent hash tables and sets, so it makes sense for them to have a reader that can process them. I really don't think this is a deal breaker though, when you can just do stuff like this: (alist->hash-table '((foo . 1) (bar . 2)))
- basketcasing 11y ago> Traditional hash tables are imperative data structures, and Lisp code (or Scheme code, at least) typically does not use them because of this. I don't understand that. > Association lists, which can be represented as literals, are persistent and provider faster lookup, despite being {snip} Those look like like they could be useful, but I don't see how they can replace hashmaps --- for one thing, they allow duplicate "keys" (the first element of each pair). I'd use a lisp, and don't mind the lisp/parens syntax, but to be useful for me it must provide easy access to and use of hashmaps and sets.
- davexunit 11y ago>I don't understand that. Introducing state into programs makes them harder to reason about, thus Scheme programmers generally discourage the use of mutable data structures when a persistent data structure would have worked. >Those look like like they could be useful, but I don't see how they can replace hashmaps --- for one thing, they allow duplicate "keys" (the first element of each pair). The way alists are used, only the first pair to contain the desired key is considered. Thus, you can "overwrite" a key/value pair by consing a new pair onto the head of the list. >I'd use a lisp, and don't mind the lisp/parens syntax, but to be useful for me it must provide easy access to and use of hashmaps and sets. I had the same initial complaints about the lack of reader syntax for hash table. It's a common complaint, actually. However, I found that as I learned more about how to write Scheme, I stopped using hash tables in any place where I used to want literal syntax for them. I learned that people reach for mutable hash tables far too frequently when there are better options available. What languages even have literal syntax for sets? I can't think of any, but I'd like to know. Reader syntax varies in each language, but I hope you can see that this really isn't a big problem at all.
- whitegrape 11y agoClojure has syntax for sets. I really like Clojure's data literals. I even think there's a Common Lisp package (or two) out there implementing reader macros to allow Clojure's syntax, but I don't think it's popular among Lispers.
- basketcasing 11y ago> > > Traditional hash tables are imperative data structures, and Lisp code (or Scheme code, at least) typically does not use them because of this. Association lists, which can be represented as literals, are persistent and {snip} > > I don't understand that. > Introducing state into programs makes them harder to reason about, thus Scheme programmers generally discourage the use of mutable data structures when a persistent data structure would have worked. Oh, maybe you typoed and meant to say that traditional hashtables are mutable data structures? In that case, I see what you mean; in Clojure, hashmaps, vectors, sets, and lists are all immutable and persistent. In Scheme, which data structures are persistent, or mutable/immutable? > The way alists are used, only the first pair to contain the desired key is considered. Ok, I see now. The function creates a hashmap from an alist. > I learned that people reach for mutable hash tables far too frequently when there are better options available. {raises hand} They're very easy to work with. In Clojure, I found myself doing extra work to work around the immutability. I'm sure it's a benefit for larger and multithreaded programs, but mine were neither. > What languages even have literal syntax for sets? I can't think of any, but I'd like to know. Clojure and Python. I suppose I could live without literal set syntax, but hashmap/hashtable syntax is extremely handy.
- lispm 11y agoBoah, I don't even know how long hash tables are in Lisp now. Hash tables became popular when the implementations used them for their symbol tables. The MIT Lisp Machine from the late 70s implemented hash tables and used them widely: http://lispm.de/source/lispm-system-78-48/lispm2/hash.lisp http://lispm.de/source/lispm-system-78-48/lispm2/hash.lisp