guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Anything better for delayed lexical evaluation than (lambda () ...)?


From: Mark H Weaver
Subject: Re: Anything better for delayed lexical evaluation than (lambda () ...)?
Date: Tue, 13 Dec 2011 14:15:03 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Andy Wingo <address@hidden> writes:
> On Tue 13 Dec 2011 18:28, Mark H Weaver <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]