bug-lilypond
[Top][All Lists]
Advanced

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

Re: bug-lilypond Digest, Vol 95, Issue 21


From: Carl Sorensen
Subject: Re: bug-lilypond Digest, Vol 95, Issue 21
Date: Fri, 8 Oct 2010 15:24:12 -0600

On 10/8/10 12:44 PM, "Roman Stawski" <address@hidden> wrote:

>  Thanks Francisco and Carl
>> The problem you had earlier was that the scheme was not evaluated during the
>> parsing stage, but during the translation stage.  And there is no implied
>> relationship between parsing order and translation order.
>> 
>> If you want stuff to happen in parsing order, it's necessary to make sure
>> the code is evaluated during parsing.
> The natural question is "how do I make sure that the counter is evaluated
> during parsing?"

Put the actual scheme expression in the input stream, rather than in a music
expression (such as a markup function) that will be put into the music tree
and evaluated during translation.

 
Note the difference in the following (original version):

\version "2.13.34"


%% This scheme expression is directly evaluated.  Its action is to create a
%% variable called sequence-number with a value of zero

#(define sequence-number 0)

%% This scheme expression is directly evaluated.  Its action is to create a
%% markup command that can be added to the parsed music tree.  The actual
%% body of the function is *not* evaluated at this time, but will be when
%% the markup function is called during translation
#(define-markup-command (score-sequence layout props) ()
 (set! sequence-number (+ sequence-number 1))
 (interpret-markup layout props
   (markup #:bold #:large (number->string sequence-number))))

\new Staff {
 %% this creates a property-set music expression that will exist in the
 %% parsed music tree, which contains the score-sequence function.  But
 %% the function is not evaluated until it's time to put the  markup on
 %% the paper.  So sequence-number isn't incremented at this time.
 \set Staff.instrumentName = \markup\score-sequence

 %% another markup function put on the music tree, to be evaluated during
 %% translation when it's time to put the markup on the paper
 a'1^\markup\score-sequence
}

\new Staff {
 %% On the music tree again, for delayed evaluation
 \set Staff.instrumentName = \markup\score-sequence

 %% On the music tree for delayed evaluation
 b'1^\markup\score-sequence
}

\new Staff {
 %% On the music tree for delayed evaluation
 \set Staff.instrumentName = \markup\score-sequence

 %% On the music tree for delayed evaluation
 c''1^\markup\score-sequence
}



My version:

\version "2.13.34"

%% This scheme expression is evaluated during parsing; it creates a variable
%% sequence-number with the value of 0
#(define sequence-number 0)

%% This is evaluated during parsing; it creates a markup function with one
%% argument
#(define-markup-command (score-sequence layout props sequence-number)
(number?)
 (interpret-markup layout props
   (markup #:bold #:large (number->string sequence-number))))

\new Staff {
 %% This is evaluated during parsing; it adds 1 to the value of
 %% sequence-number
 #(set! sequence-number (1+ sequence-number))

 %% This is evaluated during parsing; it puts a markup function on the
 %% music tree, along with its argument, which is the current value
 %% of sequence-number during the parsing stage.
 \set Staff.instrumentName = \markup\score-sequence #sequence-number

 %% This is evaluated during parsing.  It puts the markup function on
 %% the music tree, along with the current value of sequence-number
 a'1^\markup\score-sequence #sequence-number
}

\new Staff {
 %% sequence-number is incremented during parsing
 #(set! sequence-number (1+ sequence-number))

 %% the current value of sequence-number is stored in the music tree as
 %% an argument to the markup function (both calls)
 \set Staff.instrumentName = \markup\score-sequence #sequence-number
 b'1^\markup\score-sequence #sequence-number
}

\new Staff {
 %% sequence number is incremented
 #(set! sequence-number (1+ sequence-number))

 %% The new value of sequence number is stored in the music tree.
 \set Staff.instrumentName = \markup\score-sequence #sequence-number
 c''1^\markup\score-sequence #sequence-number
}
 


The general rule: if it's preceded by #, it's evaluated by the scheme
interpreter during the parsing stage.  If it's not preceded by #, it will be
evaluated during the translation stage.  (Although I won't promise this rule
*always* holds).

HTH,

Carl




reply via email to

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