I'd like to save a (extremely minimal) database made of a lisp list and then read it back.

The list will look like something as follows:

(:foo "bar" :baz "foobar" :foobaz "baz")

Are there some good ways to accomplish this?

I've tried something like this:

(with-temp-file "filename" (insert (format "%s" sample-list)))

But this discards the quotes for the strings, and I wonder if I can read them back.

I also don't know if there's some good ways to read such a file to generate a list.

1 Answer 1

(insert (format "%s" sample-list))

C-hf format tells you:

%s means produce [...] any object with ‘princ’.
%S means produce any object as an s-expression (using ‘prin1’).

See C-hig (elisp)Output Functions to understand the difference between (and relevance to your question of) princ and prin1.

(But in short, change %s to %S or, better, just use prin1 directly.)

For reading back you would typically insert-file-contents into a buffer and then read.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.