* print hash table to disk and reread in hash table
@ 2008-08-28 1:01 Xah
2008-08-28 5:21 ` Thierry Volpiatto
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Xah @ 2008-08-28 1:01 UTC (permalink / raw)
To: help-gnu-emacs
if i have a hash table in elisp, is there a way to save it to disk and
reread in when starting emacs?
Thanks.
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: print hash table to disk and reread in hash table
2008-08-28 1:01 print hash table to disk and reread in hash table Xah
@ 2008-08-28 5:21 ` Thierry Volpiatto
[not found] ` <mailman.17732.1219901096.18990.help-gnu-emacs@gnu.org>
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: Thierry Volpiatto @ 2008-08-28 5:21 UTC (permalink / raw)
To: Xah; +Cc: help-gnu-emacs
Xah <xahlee@gmail.com> writes:
> if i have a hash table in elisp, is there a way to save it to disk and
> reread in when starting emacs?
What you can do is creating a named hash-table at each time you start
emacs and load a file containing (puthash that...) (puthash this...)
etc... Here an example of one of my files:
,----
| ;;; dvc-bookmarks-cache -*- mode: emacs-lisp; coding: utf-8; -*-
| (puthash 'MAIL '((color . dvc-excluded) (state . "open") (time-stamp . "2008.06.23")) dvc-bookmarks-cache)
| (puthash 'CONFIG '((color . dvc-source) (state . "open") (time-stamp . "2008.06.23")) dvc-bookmarks-cache)
| (puthash 'DVC '((color . dvc-mark) (state . "open") (time-stamp . "2008.08.15")) dvc-bookmarks-cache)
| (puthash 'SOURCES '((color . dvc-unknown) (state . "open") (time-stamp . "2008.06.23")) dvc-bookmarks-cache)
`----
The hash-table here is `dvc-bookmark-cache'
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France
^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <mailman.17732.1219901096.18990.help-gnu-emacs@gnu.org>]
* Re: print hash table to disk and reread in hash table
[not found] ` <mailman.17732.1219901096.18990.help-gnu-emacs@gnu.org>
@ 2008-08-28 5:27 ` Xah
2008-08-28 6:17 ` Thierry Volpiatto
2008-08-28 14:03 ` Ted Zlatanov
0 siblings, 2 replies; 11+ messages in thread
From: Xah @ 2008-08-28 5:27 UTC (permalink / raw)
To: help-gnu-emacs
but is there a function or lib to save hashtable to disk? i.e.
sometimes called serializing?
Xah
∑ http://xahlee.org/
☄
On Aug 27, 10:21 pm, Thierry Volpiatto <thierry.volpia...@gmail.com>
wrote:
> Xah <xah...@gmail.com> writes:
> > if i have a hash table in elisp, is there a way to save it to disk and
> > reread in when starting emacs?
>
> What you can do is creating a named hash-table at each time you start
> emacs and load a file containing (puthash that...) (puthash this...)
> etc... Here an example of one of my files:
>
> ,----
> | ;;; dvc-bookmarks-cache -*- mode: emacs-lisp; coding: utf-8; -*-
> | (puthash 'MAIL '((color . dvc-excluded) (state . "open") (time-stamp . "2008.06.23")) dvc-bookmarks-cache)
> | (puthash 'CONFIG '((color . dvc-source) (state . "open") (time-stamp . "2008.06.23")) dvc-bookmarks-cache)
> | (puthash 'DVC '((color . dvc-mark) (state . "open") (time-stamp . "2008.08.15")) dvc-bookmarks-cache)
> | (puthash 'SOURCES '((color . dvc-unknown) (state . "open") (time-stamp . "2008.06.23")) dvc-bookmarks-cache)
> `----
>
> The hash-table here is `dvc-bookmark-cache'
>
> --
> A + Thierry Volpiatto
> Location: Saint-Cyr-Sur-Mer - France
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: print hash table to disk and reread in hash table
2008-08-28 5:27 ` Xah
@ 2008-08-28 6:17 ` Thierry Volpiatto
2008-08-28 14:03 ` Ted Zlatanov
1 sibling, 0 replies; 11+ messages in thread
From: Thierry Volpiatto @ 2008-08-28 6:17 UTC (permalink / raw)
To: Xah; +Cc: help-gnu-emacs
Xah <xahlee@gmail.com> writes:
> but is there a function or lib to save hashtable to disk? i.e.
> sometimes called serializing?
AFAIK no, may be use some python dictionary and pickle it.
> Xah
> ∑ http://xahlee.org/
>
> ☄
>
> On Aug 27, 10:21 pm, Thierry Volpiatto <thierry.volpia...@gmail.com>
> wrote:
>> Xah <xah...@gmail.com> writes:
>> > if i have a hash table in elisp, is there a way to save it to disk and
>> > reread in when starting emacs?
>>
>> What you can do is creating a named hash-table at each time you start
>> emacs and load a file containing (puthash that...) (puthash this...)
>> etc... Here an example of one of my files:
>>
>> ,----
>> | ;;; dvc-bookmarks-cache -*- mode: emacs-lisp; coding: utf-8; -*-
>> | (puthash 'MAIL '((color . dvc-excluded) (state . "open") (time-stamp . "2008.06.23")) dvc-bookmarks-cache)
>> | (puthash 'CONFIG '((color . dvc-source) (state . "open") (time-stamp . "2008.06.23")) dvc-bookmarks-cache)
>> | (puthash 'DVC '((color . dvc-mark) (state . "open") (time-stamp . "2008.08.15")) dvc-bookmarks-cache)
>> | (puthash 'SOURCES '((color . dvc-unknown) (state . "open") (time-stamp . "2008.06.23")) dvc-bookmarks-cache)
>> `----
>>
>> The hash-table here is `dvc-bookmark-cache'
>>
>> --
>> A + Thierry Volpiatto
>> Location: Saint-Cyr-Sur-Mer - France
>
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: print hash table to disk and reread in hash table
2008-08-28 5:27 ` Xah
2008-08-28 6:17 ` Thierry Volpiatto
@ 2008-08-28 14:03 ` Ted Zlatanov
2008-08-28 18:10 ` Eli Zaretskii
[not found] ` <mailman.17796.1219947087.18990.help-gnu-emacs@gnu.org>
1 sibling, 2 replies; 11+ messages in thread
From: Ted Zlatanov @ 2008-08-28 14:03 UTC (permalink / raw)
To: help-gnu-emacs
On Wed, 27 Aug 2008 22:27:47 -0700 (PDT) Xah <xahlee@gmail.com> wrote:
X> but is there a function or lib to save hashtable to disk? i.e.
X> sometimes called serializing?
No. It's easy to convert a hashtable to a list, and Emacs makes it easy
to serialize a list, so that's what people do. I have code in
gnus-registry.el (copied in part from the way Gnus saves its newsrc
file) to do this. The combination of two easy things is not,
unfortunately, simple anymore.
I like the (puthash ...) approach suggested by Thierry Volpiatto but
it's a lot of function calls for a large hashtable (which the Gnus
registry creates). So I'm not sure it's the right approach either.
BBDB has a similar problem; it saves vectors instead of lists.
If there's no library for serialization, it should definitely be
written. Emacs Lisp has only a few basic data types, and not all of
them have to be supported anyhow.
Ted
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: print hash table to disk and reread in hash table
2008-08-28 14:03 ` Ted Zlatanov
@ 2008-08-28 18:10 ` Eli Zaretskii
[not found] ` <mailman.17796.1219947087.18990.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2008-08-28 18:10 UTC (permalink / raw)
To: help-gnu-emacs
> From: Ted Zlatanov <tzz@lifelogs.com>
> Date: Thu, 28 Aug 2008 09:03:53 -0500
>
> If there's no library for serialization, it should definitely be
> written.
You mean, like bindat.el?
^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <mailman.17796.1219947087.18990.help-gnu-emacs@gnu.org>]
* Re: print hash table to disk and reread in hash table
[not found] ` <mailman.17796.1219947087.18990.help-gnu-emacs@gnu.org>
@ 2008-08-29 14:06 ` Ted Zlatanov
2008-08-29 14:52 ` Eli Zaretskii
[not found] ` <mailman.17897.1220021571.18990.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 11+ messages in thread
From: Ted Zlatanov @ 2008-08-29 14:06 UTC (permalink / raw)
To: help-gnu-emacs
On Thu, 28 Aug 2008 21:10:56 +0300 Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Ted Zlatanov <tzz@lifelogs.com>
>> Date: Thu, 28 Aug 2008 09:03:53 -0500
>>
>> If there's no library for serialization, it should definitely be
>> written.
EZ> You mean, like bindat.el?
That looks useful for binary data. I don't see from the code how to use
it to save and load a hashtable. The spec format supports these types:
;; TYPE ::= ( eval EXPR ) -- interpret result as TYPE
;; | u8 | byte -- length 1
;; | u16 | word | short -- length 2, network byte order
;; | u24 -- 3-byte value
;; | u32 | dword | long -- length 4, network byte order
;; | u16r | u24r | u32r -- little endian byte order.
;; | str LEN -- LEN byte string
;; | strz LEN -- LEN byte (zero-terminated) string
;; | vec LEN [TYPE] -- vector of LEN items of TYPE (default: u8)
;; | ip -- 4 byte vector
;; | bits LEN -- List with bits set in LEN bytes.
Is there some magic with `eval'? I didn't get it.
In addition, this library doesn't manage file I/O. I'd expect the
library do do content coding and error handling internally. This is,
actually, the most tedious part. Transforming a hashtable to a list and
back is easy (even I can write it :)
Ted
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: print hash table to disk and reread in hash table
2008-08-29 14:06 ` Ted Zlatanov
@ 2008-08-29 14:52 ` Eli Zaretskii
[not found] ` <mailman.17897.1220021571.18990.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2008-08-29 14:52 UTC (permalink / raw)
To: help-gnu-emacs
> From: Ted Zlatanov <tzz@lifelogs.com>
> Date: Fri, 29 Aug 2008 09:06:02 -0500
>
> On Thu, 28 Aug 2008 21:10:56 +0300 Eli Zaretskii <eliz@gnu.org> wrote:
>
> >> From: Ted Zlatanov <tzz@lifelogs.com>
> >> Date: Thu, 28 Aug 2008 09:03:53 -0500
> >>
> >> If there's no library for serialization, it should definitely be
> >> written.
>
> EZ> You mean, like bindat.el?
>
> That looks useful for binary data. I don't see from the code how to use
> it to save and load a hashtable.
I never used it, I just advertised the closest hit for what you seemed
to be looking.
> In addition, this library doesn't manage file I/O. I'd expect the
> library do do content coding and error handling internally. This is,
> actually, the most tedious part.
A cause for a small project, I guess. ;-)
^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <mailman.17897.1220021571.18990.help-gnu-emacs@gnu.org>]
* Re: print hash table to disk and reread in hash table
[not found] ` <mailman.17897.1220021571.18990.help-gnu-emacs@gnu.org>
@ 2008-08-29 18:10 ` Ted Zlatanov
0 siblings, 0 replies; 11+ messages in thread
From: Ted Zlatanov @ 2008-08-29 18:10 UTC (permalink / raw)
To: help-gnu-emacs; +Cc: Emacs Development
On Fri, 29 Aug 2008 17:52:07 +0300 Eli Zaretskii <eliz@gnu.org> wrote:
EZ> You mean, like bindat.el?
>>
>> That looks useful for binary data. I don't see from the code how to use
>> it to save and load a hashtable.
EZ> I never used it, I just advertised the closest hit for what you seemed
EZ> to be looking.
>> In addition, this library doesn't manage file I/O. I'd expect the
>> library do do content coding and error handling internally. This is,
>> actually, the most tedious part.
EZ> A cause for a small project, I guess. ;-)
I can just copy the code out of gnus-registry.el and abstract the
functionality to do a first cut of such a library. For a large
hashtable, though, converting to a list on the way in and out is
inefficient compared to storing it in a more "native" format. Is there
such a format, comparable to the native list read-eval format, as seen
in gnus-load:
(with-temp-buffer
(insert-file-contents file)
(while (not (eobp))
(condition-case type
(let ((form (read (current-buffer))))
(eval form))
;; ... much code omitted ...
cc to emacs-devel as I think this is of interest to that list.
Thanks
Ted
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: print hash table to disk and reread in hash table
2008-08-28 1:01 print hash table to disk and reread in hash table Xah
2008-08-28 5:21 ` Thierry Volpiatto
[not found] ` <mailman.17732.1219901096.18990.help-gnu-emacs@gnu.org>
@ 2008-08-28 8:36 ` Niels Giesen
2008-10-10 20:38 ` harven
3 siblings, 0 replies; 11+ messages in thread
From: Niels Giesen @ 2008-08-28 8:36 UTC (permalink / raw)
To: help-gnu-emacs
Xah <xahlee@gmail.com> writes:
> if i have a hash table in elisp, is there a way to save it to disk and
> reread in when starting emacs?
>
> Thanks.
>
> Xah
> ∑ http://xahlee.org/
>
> ☄
You might use this code (I use it in gimp-mode):
(defmacro gimp-hash-to-list (hash-table)
(let ((nl (gensym)))
`(let (,nl)
(maphash (lambda (k v)
(push (list k v) ,nl)) ,hash-table)
,nl)))
(defmacro gimp-list-to-hash (list)
(let ((ht (gensym)))
`(let ((,ht (make-hash-table)))
(mapc (lambda (item)
(puthash (car item) (cadr item) ,ht)) ,list)
,ht)))
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: print hash table to disk and reread in hash table
2008-08-28 1:01 print hash table to disk and reread in hash table Xah
` (2 preceding siblings ...)
2008-08-28 8:36 ` Niels Giesen
@ 2008-10-10 20:38 ` harven
3 siblings, 0 replies; 11+ messages in thread
From: harven @ 2008-10-10 20:38 UTC (permalink / raw)
To: help-gnu-emacs
Xah <xahlee@gmail.com> writes:
> if i have a hash table in elisp, is there a way to save it to disk and
> reread in when starting emacs?
You can try to convert the hash table to an alist using
gnus-hashtable-to-alist, save the alist somewhere, then read it back
at startup using gnus-alist-to-hashtable. These functions come from
gnus, the emacs mailreader, which ships with a basic emacs install.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2008-10-10 20:38 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-28 1:01 print hash table to disk and reread in hash table Xah
2008-08-28 5:21 ` Thierry Volpiatto
[not found] ` <mailman.17732.1219901096.18990.help-gnu-emacs@gnu.org>
2008-08-28 5:27 ` Xah
2008-08-28 6:17 ` Thierry Volpiatto
2008-08-28 14:03 ` Ted Zlatanov
2008-08-28 18:10 ` Eli Zaretskii
[not found] ` <mailman.17796.1219947087.18990.help-gnu-emacs@gnu.org>
2008-08-29 14:06 ` Ted Zlatanov
2008-08-29 14:52 ` Eli Zaretskii
[not found] ` <mailman.17897.1220021571.18990.help-gnu-emacs@gnu.org>
2008-08-29 18:10 ` Ted Zlatanov
2008-08-28 8:36 ` Niels Giesen
2008-10-10 20:38 ` harven
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).