help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: loading hash-table from a file?


From: Teemu Likonen
Subject: Re: loading hash-table from a file?
Date: Thu, 05 Jan 2012 11:24:14 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

* 2012-01-05T14:16:41+09:00 * ishi soichi wrote:

> 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?

Yes. Use the Lisp object printing functions to print to a buffer: PRINT,
PRIN1 or (FORMAT "%S" ...). Then read the printed object with READ which
turns it to a Lisp object again.

Here's an example of the idea:


    ;; Print
    (with-temp-file "/tmp/test"
      (let ((ht (make-hash-table)))
        (puthash 'a 1 ht)
        (puthash 'b 2 ht)
        (print ht (current-buffer))))


    ;; Read
    (with-current-buffer
        (find-file-noselect "/tmp/test")
      (let ((ht (read (current-buffer))))
        (list (gethash 'a ht)
              (gethash 'b ht))))



reply via email to

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