lilypond-devel
[Top][All Lists]
Advanced

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

Re: Solution for including a file only once


From: Michael J. O'Donnell
Subject: Re: Solution for including a file only once
Date: Thu, 11 Feb 2010 14:09:38 -0600
User-agent: Thunderbird 2.0.0.23 (X11/20090817)

Thanks, Carl. I was hunting for a music void before, and missed it. I
have several uses for it.

I'm very fuzzy on using parser vs. (ly:parser-clone parser). I have a
pretty good guess what it means technically at the low level (presumably
parser is an object with state, and the clone gives a separate local
state). I chose the clone empirically to avoid a segmentation fault.
But, ...

I now find that my solution seems to evaluate LilyPond variable definitions

    variable = {  ... }

in an acceptable context.

But Scheme variable definitions:

    #(define variable ...)

appear to define the variable only in some limited scope, so that they
aren't available globally as they would be with \include instead of
\includeIfAbsent. It's not clear to me what part of the syntax is
generating that scope, and it could even be the cloning of the parser.

I found define-public-toplevel, which can be used in the included file
(and probably should be in most cases, for greater robustness), but I'd
still like to make \includeIfAbsent work for legacy include files.

And, of course, every error of this sort that I find, springing from my
ignorance rather than just a little programming blunder, increases my
hope that someone with fuller knowledge will point out some challenging
test cases.

Cheers,

Mike O'D.

Carl Sorensen wrote:
>
> On 2/11/10 11:05 AM, "Michael J. O'Donnell" <address@hidden>
> wrote:
>
>   
>> Here's what I *now think* is correct code O:-) :
>>
>> includeIfAbsent =
>>
>> #(define-music-function (parser location fileName) (string?)
>>
>> (let ((guardName (string-append "Already Got " fileName)))
>>
>> (if (not (defined? (string->symbol guardName)))
>> (begin
>>
>> (primitive-eval (list 'define (string->symbol guardName) #t))
>>
>> (ly:parser-parse-string (ly:parser-clone parser) (string-concatenate
>> (list "\\include \"" fileName "\"")))
>>
>> #{ #}
>>     
>
> When I see #{ #}, I suspect that instead of using the substitution syntax,
> you should be using void  music functions (i.e. your return should be
> (make-music 'SequentialMusic 'void #t)).  This is the empty music you refer
> to below.
>
> You can read more about void music functions in Notation Reference 6.1.5 for
> version 2.12 or in Extending LilyPond 2.1.5 for version 2.13.
>
> Thanks,
>
> Carl
>
>
>   




reply via email to

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