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: Mon, 12 Dec 2011 00:21:21 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.91 (gnu/linux)

David Kastrup <address@hidden> writes:
> Basically I need to evaluate dynamic code in a given lexical environment
> rather than at top and/or module level.
>
> For a language that is supposed to be a building block for extension
> languages, not really a concept that is all that unusual I would think.

Guile 2 is an excellent base for building extension languages, but not
in the way that you'd like to do it.  Unfortunately, I see no way to
support `procedure-environment' on arbitrary procedures without
abandoning our optimizing compiler and going back to a simple evaluator.

I suspect it would be possible to implement a special form that captures
its lexical environment in such a way that arbitrary code could later be
evaluated within that lexical environment.  The presence of this special
form would impose onerous constraints on the optimizer within the
top-level form containing it.  In fact, I can't think of an optimization
that would still be possible, because the compiler would have to assume
the worst: that some other thread could, at any time, mutate any lexical
variable or call any lexical procedure visible from the special form.
It gets even worse when you consider first-class continuations.

I believe that this is the wrong approach, though it may be worth
considering for the sake of allowing Lilypond to continue using its
existing implementation strategy.

In general, the _right_ way to build a custom extension language using
Guile 2 is to write a compiler that converts your language into one of
the other languages that Guile 2 supports.

If there's something about Lilypond's language that you believe would
make compilation impractical, let's talk about it.  Maybe the Guile
experts on this list can find a clever solution, or else maybe we can
enhance Guile to support Lilypond's language in a straightforward
manner.

I would be glad to help with this.  In the long run, it might be less
work for us Guile hackers to implement a nice compiler for Lilypond than
to implement and forever maintain the "capture-lexical-environment"
special form, and it would almost certainly have better results.

    Regards,
      Mark



reply via email to

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