unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: David Kastrup <dak@gnu.org>
To: Mark H Weaver <mhw@netris.org>
Cc: guile-devel@gnu.org
Subject: Re: Anything better for delayed lexical evaluation than (lambda () ...)?
Date: Mon, 12 Dec 2011 07:47:38 +0100	[thread overview]
Message-ID: <87mxaycmlx.fsf@fencepost.gnu.org> (raw)
In-Reply-To: <871usaicvi.fsf@netris.org> (Mark H. Weaver's message of "Mon, 12 Dec 2011 00:21:21 -0500")

Mark H Weaver <mhw@netris.org> writes:

> David Kastrup <dak@gnu.org> 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.

Sure.  In an optimizing compiler, I would expect "procedure-environment"
to only contain actually used parts of the environment, and that would
make (procedure-environment (lambda () '())) fabulously useless.  And of
course I am not interested in the environment of that procedure, but
rather in that where procedure-environment is called.

> 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.

We are calling the Lilypond parser in that "top-level form".  The
optimizer is not much of a worry.

> 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.

Uh, we are not talking about "implementation strategy" but language
features.

> 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.

Lilypond is not Scheme.  It has syntax ambiguities that are resolved by
lexical tie-ins and thus depend on the context.  You can't easily
compile it in advance.

And you are _totally_ putting the cart before the horse here.  Lilypond
is not supposed to be an extension language for Guile, but Guile is
supposed to be an extension language for Lilypond.  The acronym Guile
stands for "GNU's Ubiquitous Intelligent Language for Extension".  You
are losing sight of what Guile is supposed to be.

As an extension language, it does not make sense that it dictates the
lexical and the program structure of the system it is supposed to be
extending.

> If there's something about Lilypond's language that you believe would
> make compilation impractical, let's talk about it.

Its syntax and semantics.

<URL:http://git.savannah.gnu.org/cgit/lilypond.git/tree/lily/parser.yy>

If I call a function with an optional argument of type integer? before
an argument of type ly:music? and I encounter #x, then the value of x
decides whether this argument will be used as the optional argument or
as the following argument.  The rest of the parsing has to follow.

> 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.

You are working from the premise that Guile should govern the
architecture of the system it is supposed to be extending.  That
Lilypond is one of the few serious systems actually using Guile as an
extension language does not make it a good idea to turn it into a system
that Guile uses as its extension.  The hard way.  With lots of work.
You can't expect that kind of investment to be done for every
application that considers using Guile.

-- 
David Kastrup



  reply	other threads:[~2011-12-12  6:47 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-03 15:45 Anything better for delayed lexical evaluation than (lambda () ...)? David Kastrup
2011-12-03 16:44 ` Andy Wingo
2011-12-06 14:55 ` Thien-Thi Nguyen
2011-12-06 15:45   ` David Kastrup
2011-12-06 19:50 ` Marco Maggi
2011-12-11  9:33   ` David Kastrup
2011-12-11  9:51     ` David Kastrup
2011-12-12  5:21     ` Mark H Weaver
2011-12-12  6:47       ` David Kastrup [this message]
2011-12-12 18:29         ` Mark H Weaver
2011-12-12 19:56           ` David Kastrup
2011-12-12 20:39             ` rixed
2011-12-12 21:02               ` David Kastrup
2011-12-12 21:58                 ` Mark H Weaver
2011-12-12 21:40             ` Mark H Weaver
2011-12-12 21:50           ` Andy Wingo
2011-12-13  9:02             ` David Kastrup
2011-12-13 13:05               ` Andy Wingo
2011-12-13 13:56                 ` David Kastrup
2011-12-13 14:34                   ` Andy Wingo
2011-12-13 15:27                     ` David Kastrup
2011-12-13 15:48                       ` Andy Wingo
2011-12-13 16:08                         ` David Kastrup
2011-12-13 16:27                           ` Andy Wingo
2011-12-13 16:54                             ` David Kastrup
2011-12-13 18:58                               ` Andy Wingo
2011-12-13 22:23                                 ` David Kastrup
2011-12-13 17:28                             ` Mark H Weaver
2011-12-13 18:49                               ` Andy Wingo
2011-12-13 19:15                                 ` Mark H Weaver
2011-12-13 23:00                                   ` Noah Lavine
2011-12-13 23:16                                     ` David Kastrup
2011-12-13 23:44                                       ` Andy Wingo
2011-12-13 23:39                                     ` Andy Wingo
2011-12-13 23:45                                       ` David Kastrup
2011-12-14 10:15                                         ` Andy Wingo
2011-12-14 10:32                                           ` David Kastrup
2011-12-14  0:30                                       ` Mark H Weaver
2011-12-14  8:16                                         ` David Kastrup
2011-12-14  0:42                                       ` Noah Lavine
2011-12-14  0:47                                       ` Noah Lavine
2011-12-14  1:30                                     ` Mark H Weaver
2011-12-14  7:50                                       ` Mark H Weaver
2011-12-14  8:48                                         ` [PATCH] Implement `capture-lexical-environment' in evaluator Mark H Weaver
2011-12-14  9:08                                           ` David Kastrup
2011-12-14  9:36                                           ` Mark H Weaver
2011-12-16  9:21                                           ` [PATCH] Implement `the-environment' and `local-eval' " Mark H Weaver
2011-12-16  9:32                                             ` David Kastrup
2011-12-16 14:00                                               ` Peter TB Brett
2011-12-16 14:26                                                 ` David Kastrup
2011-12-16 15:27                                                 ` Mark H Weaver
2011-12-16 16:01                                                   ` Andy Wingo
2011-12-16 17:44                                                     ` Mark H Weaver
2011-12-16 19:12                                                       ` Mark H Weaver
2012-01-07  1:26                                                         ` Andy Wingo
2012-01-07 17:30                                                           ` Mark H Weaver
2012-01-07  1:18                                                       ` Andy Wingo
2011-12-16 16:59                                                   ` Hans Aberg
2011-12-14 10:08                                         ` Anything better for delayed lexical evaluation than (lambda () ...)? Andy Wingo
2011-12-14 10:27                                           ` David Kastrup
2011-12-14 13:35                                             ` Andy Wingo
2011-12-14 15:21                                               ` David Kastrup
2011-12-14 15:55                                                 ` Andy Wingo
2011-12-14 17:26                                               ` Mark H Weaver
2011-12-14 18:23                                                 ` David Kastrup
2011-12-14 18:38                                                 ` Mark H Weaver
2011-12-14 19:14                                                   ` David Kastrup
2011-12-14 19:44                                                     ` David Kastrup
2011-12-14 22:56                                                 ` Andy Wingo
2011-12-14 11:03                                           ` Mark H Weaver
2011-12-14 11:18                                             ` David Kastrup
2011-12-14 13:31                                             ` Noah Lavine
2011-12-14 21:03                                               ` Mark H Weaver
2011-12-14 22:12                                                 ` David Kastrup
2011-12-14 22:24                                                   ` David Kastrup
2011-12-14 22:55                                                 ` Andy Wingo
2011-12-13 16:24                         ` David Kastrup
2011-12-13 15:52                       ` David Kastrup
2011-12-13 11:14             ` David Kastrup
2011-12-14 13:52             ` Ludovic Courtès
2011-12-14 14:27               ` David Kastrup
2011-12-14 21:30                 ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mxaycmlx.fsf@fencepost.gnu.org \
    --to=dak@gnu.org \
    --cc=guile-devel@gnu.org \
    --cc=mhw@netris.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).