libera/#commonlisp - IRC Chatlog
Search
19:44:13
engblom
doplist from alexandria seems to be able to loop over a plist with string keys, so it should be easy to convert it to a hash table by inserting each key and value.
19:47:29
engblom
Clojure has this nice syntax for hash maps: {:key1 1, :key2 2}. Is there something similar I could directly read in from a file with common lisp?
19:49:49
yitzi
There are also various packages which define a reader macro character for hash tables. Or you could just define your own.
21:25:09
pjb
engblom: I already explained to you that you that plists used only EQL to compare the keys!
21:26:29
pjb
engblom: (let* ((plist '("a" (:A 1 :B 2) "b" (:A 3 :B 4))) (keys (loop for (k) on plist by 'cddr collect k))) (loop for k in keys collect (getf plist k))) #| --> ((:a 1 :b 2) (:a 3 :b 4)) |#
21:29:11
pjb
but note that (let ((k 42)) (eq k k)) may return nil or t depending on the implementatioin!
21:30:04
pjb
so while you can find the actual string used as keys, and find them with get or getf (they use EQ to compare the keys), if the keys are numbers, you can't even be sure to be able to retrieve them!
21:31:06
pjb
engblom: if you want to be able to specify the test function, then use a-lists! assoc and rassoc take a :test argument!
21:51:52
engblom
pjb: I think hash table will be the best solution as then I only once need to specify the test function and the code will be easier to read.
21:53:49
pjb
engblom: but equal or equalp are very coarse. Good for strings, but for other keys (eg. vectors or arrays), you may want a more specific test.
22:05:22
engblom
pjb: As alexandria:plist-has-table does not recurse into the lists deeper in, it is not a problem. All the first level keys will be strings.
0:53:50
pdietz
IMO i's a good idea to look in alexandria or other such utility libraries (I like serapeum) for these sorts of things.
5:25:39
beach
phantomics: What would be the point of breaking backward compatibility for the very minor convenience to a very small number of users of Common Lisp?