lilypond-devel
[Top][All Lists]
Advanced

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

Premature evaluation.


From: David Kastrup
Subject: Premature evaluation.
Date: Thu, 15 Apr 2010 11:00:12 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.92 (gnu/linux)

Hi, in the lilypond-extending manual I find:

    %% dummy action to deal with parser lookahead
    #(display "this needs to be here, sorry!")

    #(define newLa (map ly:music-deep-copy
      (list traLaLa traLaLa)))
    #(define twice
      (make-sequential-music newLa))

    { \twice }
     [image src="lilypond/e9/lily-c0e9cdae.png" alt="[image of music]" 
text="[image of music]"]

       In this example, the assignment happens after the parser has
    verified that nothing interesting happens after `traLaLa = { ... }'.
    Without the dummy statement in the above example, the `newLa'
    definition is executed before `traLaLa' is defined, leading to a syntax
    error.

I think that's not desirable behavior.  I realize that this is partly
caused by the lexer having to call the Scheme reader in order to get a
properly delimited Scheme expression.  But there is nothing that forces
us to evaluate this expression right away.  So the Lexer could return
something like an "UNEVALED_SCM" token, and the parser could then have a
transformation rule UNEVALED_SCM -> EVALED_SCM (which obviously would
eval the expression in that course) and every construct needing an
evaled Scheme construct would specify it.  And Scheme code that was
interspersed in the grammar without context would be consumable by the
parser only in evaluated form.

Something like that.  Splitting scanning and evaluating into two should
ensure that the evaluation happens not at a time when the parsing of
preceding constructs has not yet properly completed.

-- 
David Kastrup





reply via email to

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