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: Anything better for delayed lexical evaluation than (lambda () ...)? Date: Tue, 13 Dec 2011 14:15:03 -0500 Message-ID: <87r508nv0o.fsf@netris.org> References: <87liqtpsl9.fsf@fencepost.gnu.org> <874nxdwkbi.fsf@rapitore.luna> <87d3bvfo5d.fsf@fencepost.gnu.org> <871usaicvi.fsf@netris.org> <87mxaycmlx.fsf@fencepost.gnu.org> <87wra1hcek.fsf@netris.org> <87mxaxihnw.fsf@pobox.com> <87obvclu92.fsf@fencepost.gnu.org> <87aa6wbp0w.fsf@pobox.com> <87fwgolgm5.fsf@fencepost.gnu.org> <8762hkbkwi.fsf@pobox.com> <87borclcem.fsf@fencepost.gnu.org> <87zkewa2vy.fsf@pobox.com> <87zkewjvyz.fsf@fencepost.gnu.org> <87vcpka13n.fsf@pobox.com> <87zkewnzy7.fsf@netris.org> <87r5089ui3.fsf@pobox.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1323803817 9428 80.91.229.12 (13 Dec 2011 19:16:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 13 Dec 2011 19:16:57 +0000 (UTC) Cc: David Kastrup , guile-devel@gnu.org To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Dec 13 20:16:46 2011 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 1RaXqH-0000iY-VP for guile-devel@m.gmane.org; Tue, 13 Dec 2011 20:16:46 +0100 Original-Received: from localhost ([::1]:51070 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaXqH-0002zo-0m for guile-devel@m.gmane.org; Tue, 13 Dec 2011 14:16:45 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:50873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaXqA-0002gV-90 for guile-devel@gnu.org; Tue, 13 Dec 2011 14:16:43 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RaXq8-0006TN-SP for guile-devel@gnu.org; Tue, 13 Dec 2011 14:16:38 -0500 Original-Received: from world.peace.net ([96.39.62.75]:58308) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaXq8-0006TI-Mg; Tue, 13 Dec 2011 14:16:36 -0500 Original-Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=yeeloong) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1RaXq3-0007IO-7N; Tue, 13 Dec 2011 14:16:31 -0500 In-Reply-To: <87r5089ui3.fsf@pobox.com> (Andy Wingo's message of "Tue, 13 Dec 2011 19:49:56 +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:13066 Archived-At: Andy Wingo writes: > On Tue 13 Dec 2011 18:28, Mark H Weaver writes: > >> >> (let ((xxx 2)) >> >> #{ #(set! xxx (1+ xxx)) #}) > >> In the general case, Lilypond needs to _execute_ the outer Scheme code >> before the parser/evaluator is able to even _see_ the inner Scheme code, >> because it needs to parse/evaluate the Lily code in between the two, and >> we've already established that parsing cannot be not be done without >> runtime information. > > What does it mean to execute a `(let ((xxx 2))' ? I think I need to > read the thread again, because I am really not getting it. Well, this example is a bit too simple to illustrate the point. Let's consider a slightly more complex example: (let ((xxx (foobar 1 2))) #{ #(begin (set! xxx (1+ xxx)) (let ((yyy (foobar 3 4))) #{ #(set! yyy (+ xxx yyy)) #} )) #} ) In this case, Lilypond would need to start by evaluating: (let ((xxx (foobar 1 2))) (capture-lexical-environment)) which entails evaluating (foobar 1 2), extending the lexical environment with a binding for "xxx", and then returning a new lexical environment object. Then Lilypond would then continue to parse/evaluate the Lilypond code beginning with #{, which in the general case must be done at the same time as execution. When it finds the #( it enters Scheme mode again, so it would then pass the lexical environment object from the previous step to "local-eval" with the following expression: (begin (set! xxx (1+ xxx)) (let ((yyy (foobar 3 4))) (capture-lexical-environment))) which entails mutating "xxx", evaluating (foobar 3 4) and extending the lexical environment again (which should now contain both xxx and yyy), and then returning a new lexical environment object. And so on. Does this make sense? >> How difficult would it be to implement this? > > Dunno. I was thinking that we could have a special form to return a > list of the identifiers in scope. I don't think this is sufficient. The special form must return a lexical environment object that contains everything needed by a "local-eval" procedure (which we should also provide) to evaluate arbitrary scheme code within that lexical environment. The key is that we must create the lexical environment object before we know anything about the code that will later be passed to "local-eval". Thanks, Mark