From: Mark H Weaver <mhw@netris.org>
To: Andy Wingo <wingo@pobox.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: syntax-locally-bound-identifiers, local-eval
Date: Fri, 20 Jan 2012 14:04:20 -0500 [thread overview]
Message-ID: <874nvqw5zf.fsf@netris.org> (raw)
In-Reply-To: <87r4yutuj4.fsf@pobox.com> (Andy Wingo's message of "Fri, 20 Jan 2012 13:42:23 +0100")
Hi Andy. Thanks for following through on this. As you probably
noticed, my motivation to work on `local-eval' has largely dissipated,
so it's great that you finished this up in time for 2.0.4.
I haven't yet had time to fully review these patches, but for now, a
quick scan reveals a few remaining problems. See below:
Andy Wingo <wingo@pobox.com> writes:
> +(define-syntax the-environment
> + (lambda (x)
> + (syntax-case x ()
> + ((the-environment)
> + #'(the-environment the-environment))
> + ((the-environment scope)
> + (call-with-values (lambda ()
> + (analyze-identifiers
> + (syntax-locally-bound-identifiers #'scope)))
> + (lambda (capture formals wrappers patterns)
> + (define (wrap-expression x)
> + (let lp ((x x) (wrappers wrappers))
> + (if (null? wrappers)
> + x
> + (lp ((car wrappers) x) (cdr wrappers)))))
> + (with-syntax ((module (datum->syntax #'here (module-name (current-module))))
***** Again, the module must be the one embedded in `scope', not the
(current-module). I guess this is a reminder that I need to add a more
thorough set of regression tests for `local-eval'.
> +(define (local-eval x e)
> + "Evaluate the expression @var{x} within the lexical environment @var{e}."
> + (cond ((lexical-environment? e)
> + (apply (eval (local-expand x e) (lexenv-module e))
> + (lexenv-boxes e)))
> + ((module? e)
> + ;; Here we evaluate the expression within `lambda', and then
> + ;; call the resulting procedure outside of the dynamic extent
> + ;; of `eval'. We do this because `eval' sets (current-module)
> + ;; within its dynamic extent, and we don't want that. Also,
> + ;; doing it this way makes this a proper tail call.
> + ((eval #`(lambda () #,x) e)))
***** Again, there should be an `#f' before `#,x' here, to force
expression context (my mistake).
> + (else (error "local-eval: invalid lexical environment" e))))
> +
> +(define* (local-compile x e #:key (opts '()))
> + "Compile and evaluate the expression @var{x} within the lexical environment @var{e}."
> + (cond ((lexical-environment? e)
> + (apply (compile (local-expand x e)
> + #:env (lexenv-module e)
> + #:from 'scheme #:opts opts)
> + (lexenv-boxes e)))
> + ((module? e)
> + ;; Here we compile the expression within `lambda', and then
> + ;; call the resulting procedure outside of the dynamic extent
> + ;; of `compile'. We do this because `compile' sets
> + ;; (current-module) during evaluation, and we don't want that.
> + ((compile #`(lambda () #,x)
***** Ditto.
> + #:env e #:from 'scheme #:opts opts)))
> + (else (error "local-compile: invalid lexical environment" e))))
I'll try to do a more thorough review later.
Thanks,
Mark
next prev parent reply other threads:[~2012-01-20 19:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-20 12:33 syntax-locally-bound-identifiers, local-eval Andy Wingo
2012-01-20 12:42 ` Andy Wingo
2012-01-20 19:04 ` Mark H Weaver [this message]
2012-01-20 20:00 ` Mark H Weaver
2012-01-22 7:01 ` Mark H Weaver
2012-01-23 12:52 ` Andy Wingo
2012-01-25 23:44 ` Andy Wingo
2012-01-22 0:28 ` Ludovic Courtès
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=874nvqw5zf.fsf@netris.org \
--to=mhw@netris.org \
--cc=guile-devel@gnu.org \
--cc=wingo@pobox.com \
/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).