Pardon my newbieness, but is there a way to load expressions from a
file without evaluating them? IIUC, load sequentially evaluates
everything it loads; what I'd need is a "load-quoted" function.
Or alternatively, is there a more intelligent way to manipulate a
program contained in a source file, and then write the new program
back to a file?
I know this may sound like I'm in this a bit over my head, which
probably is the case, but thank you for your patience :)
"Nyang A. Phra" <······@gmail.com> writes:
> Pardon my newbieness, but is there a way to load expressions from a
> file without evaluating them? IIUC, load sequentially evaluates
> everything it loads; what I'd need is a "load-quoted" function.
So you don't want to load, you want to READ.
(with-open-file (stream "/some/file") (read stream))
If you want to read several forms:
(with-open-file (stream "/some/file")
(loop :for form = (read stream nil stream)
:until (eq form stream)
:collect form))
You may also want to bind *read-eval* to nil to prevent #. evaluation.
> Or alternatively, is there a more intelligent way to manipulate a
> program contained in a source file, and then write the new program
> back to a file?
http://darcs.informatimago.com/lisp/common-lisp/source-text.lisp
http://www.informatimago.com/develop/lisp/index.html
Or you can also process sources from emacs, have a look at map-sexps
et al. in:
http://darcs.informatimago.com/emacs/pjb-sources.el
--
__Pascal Bourguignon__
In article
<····································@e23g2000prf.googlegroups.com>,
"Nyang A. Phra" <······@gmail.com> wrote:
> Pardon my newbieness, but is there a way to load expressions from a
> file without evaluating them? IIUC, load sequentially evaluates
> everything it loads; what I'd need is a "load-quoted" function.
>
> Or alternatively, is there a more intelligent way to manipulate a
> program contained in a source file, and then write the new program
> back to a file?
You could just use READ.
(defun read-all-forms-from-stream (stream)
(loop with eof = '#:eof
for form = (read stream nil eof)
until (eq form eof)
collect form))
(defun read-all-forms (file)
(with-open-file (stream file)
(read-all-forms-from-stream stream)))
>
> I know this may sound like I'm in this a bit over my head, which
> probably is the case, but thank you for your patience :)
NAP> Or alternatively, is there a more intelligent way to manipulate a
NAP> program contained in a source file, and then write the new program
NAP> back to a file?
do you want to preserve original formatting and comments?
if you don't, simple READ would do that
> do you want to preserve original formatting and comments?
> if you don't, simple READ would do that
No, no need to preserve formatting. So READ it is, thanks, everyone.