libera/#commonlisp - IRC Chatlog
Search
11:09:23
jcowan
You can discuss Coalton here, or of course in #lisp: it is a Lisp, so on-topic there
16:17:50
lisp123
Is there a optimal way to create a hash table with a custom test function, without defining your own hash function to go alongside the test condition?
16:27:20
pjb
You can create a hash-table with a test function AND a hash function. Note that sxhash is provided, but 1- it's not generic, 2- it's not necessarily good for your objects, 3- it's not used by CL hash-tables (or at least, it's implementation dependent whether it's used or not).
16:28:02
pjb
If by "optimal" you mean with minimal programmer effort, then you can create a hash-table as a wrapper with a custom test and hash-function using cl:hash-table to avoid having to re-implement everything.
16:28:28
pjb
lisp123: then, perhaps you have all the keys in advance? There are algorithms to create perfect hash-functions given a known list of keys.
16:30:28
pjb
Or you can write a wrapper computing the key: (defun get-my-key (list) (list (first list) (third list))) (setf (gethash (get-my-key (my-object-list object)) table) object)
16:32:05
lisp123
I have a function which can match two lists and disregard any discrepancies where there is a *
16:32:39
pjb
lisp123: if you have a finite number of combinations, you can have multiple entries in the hash-table.
16:34:07
pjb
And since possibly each pattern can match several object, you'd rather use push than setf.
16:34:19
pjb
(dolist (combination (compute-keys object)) (push object (gethash combination '()) table))
16:39:31
pjb
Then if you have lists, or similarly structured keys, you could have a tree of hash-tables.
16:41:23
pjb
(defun select (key table) (cond ((null table) nil) ((null key) table) ((eql '* (first key)) (mapcan (lambda (table) (select (rest key) table)) (hash-table-elements table))) (t (select (rest key) (gethash (first key) table)))))
16:59:20
pjb
pve: it may lack a ensure-list somewhere but the idea is that when there's a *, there may be multiple hits. So we return a list of results.
17:13:20
pjb
pve: you're right, I need to copy the list build by pushnew, otherwise it's made circular…
17:16:35
pjb
with (setf select) you cannot have a wildcard. (* is just taken as a key, but it couldn't be retrieved alone with (select).
18:33:39
ln43
ok... i was starting reading paip but aima is the recommended book for AI looking around
18:34:26
ln43
anyway ok... i will try to read both but is better start from only one to avoiid any possible confusion
18:40:01
ln43
but looking at the contents of PAIP is not almost the same as AIMA4e ... at least all the algorithms are not included
18:40:45
pjb
It would have been too big to include all of them. And so, they're left as an exercise for the reader.
18:41:35
ln43
ok, I was asking just to know if there was an interest in the CL community to have the code available for further exploration using M-. and M-, that is the approach i'm currently using
18:42:45
_death
AIMA is very different from PAIP, but both have CL source code associated with them.. I don't know about the fourth edition specifically
18:45:21
pjb
Well, eventually Norvig turned to Python, for the money in it, so obviously he didn't maintain the lisp code for the newer editions.
18:46:17
pjb
Indeed. Now you can fork, contribute, and send a PR, but somehow I doubt it'd be merged soon.
18:47:06
Josh_2
How do you open the inspector in SLIME? Normally I just click on an object in sly and it opens up.
18:47:25
ln43
only 1 contributor to only port all that is contained in https://github.com/aimacode/aima-pseudocode is not enough