Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 790
Toerndev Avatar asked May 05 '11 02:05

Toerndev


1 Answers

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*)
like image 74
Terje Norderhaug Avatar answered Sep 18 '22 12:09

Terje Norderhaug