From: Mark H Weaver <mhw@netris.org>
To: David Kastrup <dak@gnu.org>
Cc: guile-devel@gnu.org
Subject: Re: [PATCH] local-eval, local-compile, and the-environment (v3)
Date: Mon, 16 Jan 2012 00:46:47 -0500 [thread overview]
Message-ID: <87vcoc2o8o.fsf@netris.org> (raw)
In-Reply-To: <87mx9o1z4n.fsf@fencepost.gnu.org> (David Kastrup's message of "Sun, 15 Jan 2012 21:36:56 +0100")
David Kastrup <dak@gnu.org> writes:
> guile> (let ((x 2)) (eval '(begin (define x 4) x) (current-module)))
> 4
> guile> x
> 4
> guile>
>
> Right through to the top. And we couldn't do that in local-eval. But
> it also has no qualms just because previously evaluated forms would have
> used a previous definition of x. But that's because of top-level. Eval
> is always top-level, and define acts like set! there.
Yes, top-level is a very different animal than an internal body, despite
the superficial syntactic similarities.
> What if the-environment had been taken at top-level (basically just
> carrying the information of (current-module))? Should local-eval then
> behave accordingly? If so, could we not just fold eval and local-eval
> into one function?
This is a good question. Unfortunately, there is a non-trivial
difference in the semantics of `eval' vs `local-eval'.
`eval' temporarily sets the (current-module) to its second argument
during evaluation of the expression.
`local-eval' does not do this, and as I recall that was something you
felt strongly about (and I agree).
> And one could then define
> (define current-module
> (let ((top-level (the-environment)))
> (lambda () (eval '(the-environment) top-level))))
> if the-environment just returns the current module when at top level?
I see what you're getting at, but this would be a bad idea, because it
still makes sense to have `module' be an independent type.
Also, in the code above, `top-level' would not actually be a top-level
environment, because (the-environment) is not a top-level form. If you
put (define x 5) in place of (the-environment), it would not set a
top-level variable; it would produce an error.
Mark
next prev parent reply other threads:[~2012-01-16 5:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-15 6:27 [PATCH] local-eval, local-compile, and the-environment (v3) Mark H Weaver
2012-01-15 15:39 ` David Kastrup
2012-01-15 17:14 ` Mark H Weaver
2012-01-15 17:38 ` David Kastrup
2012-01-15 18:15 ` Mark H Weaver
2012-01-15 18:26 ` David Kastrup
2012-01-15 19:06 ` Mark H Weaver
2012-01-15 19:24 ` David Kastrup
2012-01-15 19:52 ` Mark H Weaver
2012-01-15 20:12 ` David Kastrup
2012-01-15 20:36 ` David Kastrup
2012-01-16 5:46 ` Mark H Weaver [this message]
2012-01-16 7:46 ` David Kastrup
2012-01-16 7:57 ` Mark H Weaver
2012-01-16 8:44 ` Mark H Weaver
2012-01-16 9:07 ` Mark H Weaver
2012-01-16 9:34 ` David Kastrup
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/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87vcoc2o8o.fsf@netris.org \
--to=mhw@netris.org \
--cc=dak@gnu.org \
--cc=guile-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.
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).