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 12:05:26 -0600
User-agent: Thunderbird 2.0.0.23 (X11/20090817)

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 "\"")))

#{ #}

)

#{ #}

) ) )

It appears to include/not include appropriately in a project that I'm
working on. When I failed to clone the parser, I got desired *.ps and
*.pdf output, but a segmentation fault at the end, presumably due to
putting the parser in a bad state. I'm a bit uncomfortable with the
empty braces #{ #}, which were necessary so that the "music" function
includeIfAbsent would return some rather empty music. I'm uncomfortable
because LilyPond design so far seems to have neglected the notion of
empty music (similar to the null markup, which it includes), and because
it's not clear to me why head material of this sort needs to be
classified as music at all.

I don't understand the interaction of Scheme variable scope with
LilyPond syntax, so I'm not sure how this will behave in contexts other
than toplevel. And I don't know the right sort of comprehensive test
cases. If anybody can beat on it, please do.

Cheers,

Mike O'D.





reply via email to

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