Andreas Hinze said:
> Hi all, > ;; i'm terrible late with this question but have overseen this > ;; mail until now, sorry. > >>-----Original Message----- >>From: Pierre R. Mai [mailto:[EMAIL PROTECTED]] >>Sent: Thursday, August 08, 2002 12:54 AM >>To: Mario S. Mommer >>Cc: [EMAIL PROTECTED] >>Subject: Re: writing double-floats to binary streams >> > [cut] >> >> >>There is also the more portable trick of using #. in conjunction with >> compile-file to save objects, but that isn't that convenient... >> > Can anyone please be so kind to explain this trick ? I didn't realize it > (raises a newbie-exception ;-) and can't find any hint. The trick involves creating a lisp source file that embeds the to be saved data as a literal via #., and then compiling this file via compile-file. Prerequisite is the existance of make-load-form methods for all contained data, as per usual for externalization of literal data. For example you have your persistent state to be in the special variable *my-data*. Then the following code will create a FASL file, which when loaded will restore the value of *my-data* to its current value: (defvar *my-data* ...) ... mutate *my-data* ... (defun save-my-data (basename) (let* ((source-path (make-pathname :type "lisp" :defaults basename)) (fasl-path (compile-file-pathname source-path))) (with-open-file (stream source-path :direction :output) (write-line "(in-package :MY-PACKAGE)" stream) (write-line "(setq *my-data* #.*my-data*)" stream)) (compile-file source-path) ;; Delete source-path here, probably in an unwind protect. ;; You might also want to generate a unique temp name for ;; source-path, and/or use the output-file option to ;; compile-file to get a nice non-FASL name for your data ;; file... fasl-path)) This would be more convenient, if compile-file would portably accept a string-stream as the source file, like e.g. compile-from-stream does for CMUCL, which would allow building the source text in core, instead of going out to a temporary file. Regs, Pierre. PS: Mailed via newfangled PMSF WebMail facility, so excuse any evil formatting, etc. -- Pierre R. Mai <[EMAIL PROTECTED]> http://www.pmsf.de/pmai/ The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents. -- Nathaniel Borenstein
