libera/#commonlisp - IRC Chatlog
Search
19:36:04
White_Flame
depending onthe size of your tables, you might want to consider hashtables as well
19:36:13
engblom
White_Flame: Is it possible to nest alists, like I have done in the pasted example? Or would you keep the inner list as a plist?
19:36:40
White_Flame
but key=>value is just data. the outer container doesn't care what's inside the value slots
19:37:28
White_Flame
however, I think the one advantage that plists have is that you can (setf (getf ...) ..), which I don't think you can do as simply with alists
19:38:10
engblom
White_Flame: The lists will be around 100 pairs long, so hastables are probably overkill. Besides, the lists are actually are actually handwritten in a configuration file and then read in by read-from-file
19:38:57
White_Flame
that handwritten form doesn't need to be the canonical format at runtime, though. You can read it in as an easy-to-hand-edit list, and then store it in another format, too
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?