Hi,
I was wondering if there is a built-in way to eval the contents of a
file inside of an environment other than (current-module)? We have eval
and primitive-eval, and it seems that load is currently (conceptually) a
read, primitive-eval loop until eof is reached. Why not allow an
environment arg to load, making it (conceptually) a read, eval loop
until eof is reached?
There are two ways that I've thought of to implement this if it is not
implemented in guile already (which it doesn't seem to be). One is to
simply read the file repeatedly, and eval the results in the given
environment:
(define load-env-1 filename env)
(let* ((file (open-input-file filename))
(datum (read file)))
(while (not (eof-object? datum))
(eval datum env)
(set! datum (read file))))
The second way is to make the desired environment temporarily be the
current module:
(define load-env-2 filename env)
(let ((real-current-module (current-module)))
(set-current-module! env)
(load filename)
(set-current-module! real-current-module)))
The second way has the advantage of not reinventing the wheel when it
comes to the read-eval loop, but looks rather strange. If anyone knows
of a better way to do this, or especially if someone knows of a
procedure already in guile to do exactly this, I'd love to hear about
it. If anyone has thoughts on ways that one or both of these might be
improved, I'd also love to hear about that.
Regards,
Jon
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user