[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Understanding ly:parser-include-string
From: |
Urs Liska |
Subject: |
Re: Understanding ly:parser-include-string |
Date: |
Wed, 27 Jan 2016 19:01:09 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 |
Am 27.01.2016 um 18:22 schrieb David Kastrup:
> Urs Liska <address@hidden> writes:
>
>> Hi,
>>
>> I'm running into an issue with including files using
>> ly:parser-include-string.
>>
>> The underlying task is that I want to conditionally include files, so I
>> have the pseudo-code:
>>
>> #(if (some-condition)
>> (ly:parser-include-string "\\include \"some-file.ily\""))
>>
>> This works pretty well for single items. It is also possible to insert
>> multiple \include-s in the string, and all files are loaded. However,
>> when a file defines anything, subsequently included files don't have
>> access to it. It seems the whole conditional expression has to be
>> evaluated until the new definitions are available.
> Of course it has. You are in the middle of the interpretation of a
> Scheme form. ly:parser-include-string works with the _current_ parser
> by default. Something like
>
> #(ly:parser-include-string "theme = { c1 d }")
>
> \addlyrics { Hi ho }
>
> \displayMusic \theme
>
> creates a single music expression and displays it. How would that work
> if you wanted to reference `theme' in the expression itself? If you
> want an _independent_ parser, clone it.
>
> #(begin
> (ly:parser-parse-string (ly:parser-clone)
> "\\language #default-language
> theme = { c1 d }")
> (displayScheme theme))
>
> \displayLilyMusic \theme
>
> will work as expected, using a fresh parser. Note that the cloned
> parser will not have a language set by default.
Thank you very much. I have the impression that this will already help
me through ...
>> And if I only include this single some-file.ily this can again include
>> multiple files (with regular LilyPond syntax). And again, files
>> included that way don't have access to definitions (variables,
>> functions) that are in files included earlier.
> I have no idea what you are talking about here.
>
> ...
>
>> And is there a solution for my original problem: conditionally
>> including files with multiple secondary includes?
> There is no problem with that.
>
I should be able to give better description or a short example. But
hopefully the first part of your post will have made this obsolete ...
Best
Urs