From: Valentin Baciu <valentin@syntactic.org>
To: ishi soichi <soichi777@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: loading hash-table from a file?
Date: Thu, 5 Jan 2012 10:35:18 +0200 [thread overview]
Message-ID: <CAKHQLnrp9598wU8DU0KTRV1sJ267cMKrk3Hfgz43kpo7AKMrNw@mail.gmail.com> (raw)
In-Reply-To: <CAEjRLuSVMqrjXLX5nHwR08Hp3pmkTC-WsJnx5tj35bXAbQzMEQ@mail.gmail.com>
On Thu, Jan 5, 2012 at 7:16 AM, ishi soichi <soichi777@gmail.com> 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
work.
;; 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))
(save-buffer)))
;; Reading back the hash-table object
(type-of (read (find-file-noselect "/tmp/x")))
;; hash-table
next prev parent reply other threads:[~2012-01-05 8:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-05 5:16 loading hash-table from a file? ishi soichi
2012-01-05 8:35 ` Valentin Baciu [this message]
2012-01-05 9:11 ` Teemu Likonen
2012-01-05 9:13 ` ishi soichi
2012-01-05 9:07 ` Eric Abrahamsen
2012-01-06 16:43 ` Thierry Volpiatto
2012-01-07 2:16 ` Eric Abrahamsen
2012-01-05 9:24 ` Teemu Likonen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAKHQLnrp9598wU8DU0KTRV1sJ267cMKrk3Hfgz43kpo7AKMrNw@mail.gmail.com \
--to=valentin@syntactic.org \
--cc=help-gnu-emacs@gnu.org \
--cc=soichi777@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.