[Top][All Lists]

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

Re: summary: lilypond, lambda, and local-eval

From: Hans Aberg
Subject: Re: summary: lilypond, lambda, and local-eval
Date: Thu, 15 Dec 2011 18:52:35 +0100

On 15 Dec 2011, at 18:24, David Kastrup wrote:

>>> The "delayed evaluation" thread is a bit long and confusing, so I would
>>> like to try to summarize it.
>>> Lilypond has a way to embed Lilypond code in Scheme, and Scheme code in
>>> Lilypond code.  The former uses a reader macro, #{#}.  The latter uses
>>> specially-marked variables and expressions, specifically, those preceded
>>> by $ or #.
>> ...
>>> It took some time for everyone to understand the problem.  In the end,
>>> there were four workable possibilities.
>>> 1) Keep using closures.
>> When doing a parser on top of Guile, I noticed one must first build an
>> unevaluated closure, and only thereafter call the evaluator. Scheme
>> has some restrictions forcing this, for example, the lambda cannot
>> appear as a free symbol, though it is possible in Guile using
>> scm_sym_lambda.
>> It might be useful with a variation of scm_eval_string() that only
>> parses and builds the closure, but not calls the evaluator.
> I am not sure what you mean with "closure" here, but just "read" parses
> a form.

I build them from scratch, using the scm_x calls, with a parser. This way, it 
is possible to a more than within the Scheme paradigm itself. For example,
  scm_list_x(scm_sym_lambda, ...)
gives an unevaluated lambda-expression. Some symbols are not available in 
Guile, so for example, I have in my init():
  SCM list_ = scm_from_locale_symbol("list");

After an expression has been built, the parser calls scm_primitive_eval(). 
However, suppose one wants to insert some Scheme code in to the expression, 
then scm_eval_string() will call the evaluator, enforcing that only complete 
Scheme expressions can be inserted:

Without that restriction it would be possible to have an expression like
  f := x |-> scheme "(+ x 1)"
where only the quote is the actual scheme code and the other handled by the 
external parser, and where the external "x" binds to the one in the Scheme code 
string "(+ x 1)". However, when scm_eval_string() calls the evaluator, one gets 
an error, because "x" is not bound.


reply via email to

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