[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: loading hash-table from a file?

From: Valentin Baciu
Subject: Re: loading hash-table from a file?
Date: Thu, 5 Jan 2012 10:35:18 +0200

On Thu, Jan 5, 2012 at 7:16 AM, ishi soichi <> wrote:
> I have never used hash-table of Emacs Lisp but I believe it's useful as a
> database.
> Say, I have a hundred key-value pairs, which are to be stored as
> hash-table.
> Can I save this as a (text?) file so that Emacs can load it when booting up?
> I am a little confused because if I use (cons key value), it outputs "(key .
> value)" which can be written in a regular file.
> If I wish to find the value from a key, all I need to do is to simply search
> through the file.
> Do you think I can save the database using hash-table like this?
> soichi

In my Emacs 24, I can read back a printed (simple) hash table. I am
not sure weather using more complex data types as values will also

;; Writing the hash table to a "database" file

(with-current-buffer (find-file-noselect "/tmp/x")
  (let ((h (make-hash-table)))
    (puthash 'a 0 h)
    (puthash 'b 1 h)
    (insert (format "%s" h))

;; Reading back the hash-table object

(type-of (read (find-file-noselect "/tmp/x")))
;; hash-table

reply via email to

[Prev in Thread] Current Thread [Next in Thread]