(let ((myhash (make-hash-table :test 'equal)))
(setf (gethash "name" myhash) "andrew"
(gethash "location" myhash) "sf"))
Instead of `#{"name" "andrew" "location" "sf"}`. '((name . "andrew") (location . "sf"))
(Incidentally, you probably don't really want 'name and 'location to be strings.)It's curious that no quasi-standard reader macro for hash literals developed, though.
It's not a lot of code or too complex to do that, but it's not obvious either and some people got it wrong or do it differently and I think that made reader modifications less common than they otherwise might have been.
I haven't looked too closely at the details but some of cl21's changes look like they might try to address this issue.
But even if a more compact way of constructing hash tables is called for, why a literal syntax instead of a more compact constructor? E.g. you could write
(dict "name" "andrew" "location" "sf")
with a compiler macro that produces exactly the above code.(let ((myhash (make-hash-table :test 'equal))) (add-hash-entry (("name" "Andrew") ("location" "sf")) myhash)
Which seems, to me, easier than having more special-case syntax to learn.
But I suspect this may be one of the drawbacks of Lisp, (indeed, it may turn out to be a problem with any powerful programming language.) It's so absurdly easy to do things like that, that incremental advances can be retarded by virtue of the steps along the way not being shared. And then when someone has to come along and use what you've written, without having been there for the steps along the way, the base level of abstraction they have to build up from is too low.
Here's the code for basic hashtable syntax:
If something annoys you (like funky function names) you can alias them or add whatever you think is missing to the language.
E.g. You could define second as something like
(defun second (list) (nth 1 list))
and use it forever, just as if it were in the base language.
As an example I have a function L2HT which takes a list and returns a hash table:
(l2ht '((1 "one") (2 "two)))
(You can override the hash table type with various parameters if you like).
It's easy to add to CL, btw.