[Top][All Lists]

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

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

From: David Kastrup
Subject: Re: Anything better for delayed lexical evaluation than (lambda () ...)?
Date: Wed, 14 Dec 2011 00:16:10 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Noah Lavine <address@hidden> writes:

> Hello,
> I haven't really been contributing to this thread, so please take my
> opinion with a grain of salt. But it does appear to me that we should
> support capturing a lexical environment, as Mark and David describe.
> So I took a look at ice-9/eval.scm to see how difficult it would be to
> implement. Offhand, it doesn't look bad: the eval function there
> already passes around environment objects, so if it hit this special
> form, it would simply return its environment object (probably packaged
> up in a record so it would print nicely). Restarting it is also
> simple: call eval on an expression with the given environment. The
> environment objects already contain all of the information needed to
> evaluate expressions, so I don't think there is very much to do there.
> The part that seems more interesting to me is that Guile's evaluator
> attempts to memoize an entire expression before evaluating any of it,
> which I understand is impossible with Lilypond. I assume Lilypond
> handles this by bundling the Lilypond code into a string (or some
> other object), letting the memoizer look at that, and then later doing
> the actual expansion. David, is this how you handle that?

guile> '#{ \relative c' { $p 2  \mark #4 } #}
(#<procedure embedded-lilypond (parser lily-string filename line closures)> 
parser " \\relative c' { $p 2  \\mark #4 } " #f 2 (list (cons 17 (lambda () 

In this case, $p is placed into a lambda together with its offset in the
string.  The whole thing is a function call to a procedure that clones
the current parser and let's it parse the enclosed string.  Filename and
line are just tracked for providing useful error messages.  #4 is not
turned into a lambda since it is an obvious constant.

The obvious wishlist item would be to replace the potentially long and
expensive to create argument "closures" (which needs to get consed
together on each call since (lambda () p) needs to be created in the
current environment) with (package-environment).

I have no reliable idea what "memoize" means exactly in Guile's
terminology, and the parts of the manual I have consulted have no qualms
using this expression, but don't bother explaining it.

David Kastrup

reply via email to

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