unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: emacs-devel@gnu.org
Subject: Re: persistent lisp objects
Date: Thu, 01 Oct 2009 10:14:24 +0200	[thread overview]
Message-ID: <87ljjv5y5b.fsf@tux.homenetwork> (raw)
In-Reply-To: 871vlqt9rv.fsf@tux.homenetwork

Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:

> Hi all,
> it seem using `setf' combined with `eval-when-compile' is a convenient
> way to save lisp object like hash-table.
> It is not documented.
> What do you think?

Maybe i was not clear enough.
We can actually save any lisp object in a compiled file:

,----
| (defun tv-dump-object-to-file (obj file)
|   "Save symbol object `obj' to the byte compiled version of `file'.
| `obj' can be any lisp object, list, hash-table, etc...
| `file' is an elisp file with ext *.el.
| Loading the *.elc file will restitute object."
|   (require 'cl) ; Be sure we use the CL version of `eval-when-compile'.
|   (if (file-exists-p file)
|       (error "File already exists.")
|       (with-temp-file file
|         (erase-buffer)
|         (let* ((str-obj (symbol-name obj))
|                (fmt-obj (format "(setq %s (eval-when-compile %s))" str-obj str-obj)))
|           (insert fmt-obj)))
|       (byte-compile-file file) (delete-file file)
|       (message "`%s' dumped to %sc" obj file)))
`----

This is a feature of `eval-when-compile' that is not documented.
It can be interesting as AFAIK there is no way to save object.

-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France





  reply	other threads:[~2009-10-01  8:14 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-29  8:50 persistent lisp objects Thierry Volpiatto
2009-10-01  8:14 ` Thierry Volpiatto [this message]
2009-10-07 16:53   ` Drew Adams
2009-10-07 22:03     ` Stefan Monnier
2009-10-07 22:10       ` Drew Adams
2009-10-08  5:11         ` Stephen J. Turnbull
2009-10-25 10:33           ` Thierry Volpiatto
2009-10-25 10:26       ` Thierry Volpiatto
2009-10-25 15:05         ` Stefan Monnier
2009-10-27 20:18         ` Ted Zlatanov
  -- strict thread matches above, loose matches on Subject: below --
2009-10-02 20:55 MON KEY
2009-10-03  3:36 ` Stefan Monnier
2009-10-03 19:19   ` MON KEY
2009-10-03 20:13 ` Richard Stallman
2009-10-04  0:15   ` MON KEY
2009-10-04 21:03     ` Richard Stallman

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ljjv5y5b.fsf@tux.homenetwork \
    --to=thierry.volpiatto@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).