From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: syntax-locally-bound-identifiers, local-eval Date: Fri, 20 Jan 2012 14:04:20 -0500 Message-ID: <874nvqw5zf.fsf@netris.org> References: <87vco6tuxy.fsf@pobox.com> <87r4yutuj4.fsf@pobox.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1327086333 32631 80.91.229.12 (20 Jan 2012 19:05:33 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 20 Jan 2012 19:05:33 +0000 (UTC) Cc: guile-devel To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Jan 20 20:05:25 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RoJm4-0007JI-HA for guile-devel@m.gmane.org; Fri, 20 Jan 2012 20:05:20 +0100 Original-Received: from localhost ([::1]:49600 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RoJm3-0004dX-Ap for guile-devel@m.gmane.org; Fri, 20 Jan 2012 14:05:19 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:40987) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RoJm1-0004dS-31 for guile-devel@gnu.org; Fri, 20 Jan 2012 14:05:18 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RoJlv-0002Qr-87 for guile-devel@gnu.org; Fri, 20 Jan 2012 14:05:17 -0500 Original-Received: from world.peace.net ([96.39.62.75]:36300) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RoJlv-0002Qn-0f for guile-devel@gnu.org; Fri, 20 Jan 2012 14:05:11 -0500 Original-Received: from c-98-216-245-176.hsd1.ma.comcast.net ([98.216.245.176] helo=yeeloong) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1RoJlo-000843-LR; Fri, 20 Jan 2012 14:05:05 -0500 In-Reply-To: <87r4yutuj4.fsf@pobox.com> (Andy Wingo's message of "Fri, 20 Jan 2012 13:42:23 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 96.39.62.75 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:13602 Archived-At: 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 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