Write/read a Common Lisp (SBCL) hash-table, or alternative
Asked Answered
R

1

6

I would like to write/read a hash-table to/from disk, but it is not a (print)able object. I won't know the key names so I can't think of a way to do it manually. I read that there might be distribution-specific ways to do this; is there anything for this in SBCL?
I didn't find anything in the SBCL manual or on Google.

If not, is there another, storable way to keep lists of integers bound to strings, be able to modify those lists efficiently, and have constant or at least faster-than-alist access time?
Are binary search trees easy enough to implement with alists and is that a good idea for making a basic database?

Residuary answered 5/5, 2011 at 2:28 Comment(0)
C
12

MAPHASH maps a function with two arguments over a hash table for side effects. The two arguments are the key and value of each item in the hash table. You can use this to for example write each item in the hash table as a list of the key and value:

(maphash (lambda (key value)(write (list key value))) *hash-table*)
Caseate answered 5/5, 2011 at 2:40 Comment(2)
@dsolimano Thanks, I know, it did solve my problem but I felt that some more of the questions could have been answered. Anyway it's checked now.Residuary
Hmm. Reading the question I was really hoping for something close to the dict literal in python at least. Or an output version of the hash table that the Reader reads. I guess it could be hacked up with reader macros.Pash

© 2022 - 2024 — McMap. All rights reserved.