Leo Correia de Verdier <[email protected]> writes:
> Dear list!
>
> Is there a way to have an \include inside a function?
> In the attached file includeinfunction.ly the commented out line
> doesn’t work (probably for some very logical reason, but still unknown
> to me).
Uh, if you write the content of the included file _exactly_ where
\include #filename now is, you get _exactly_ the same error. Your
inclusion works perfectly fine. It's just that the syntax in the file
is not valid syntax inside of #{ ... #}.
If you want to include the file instead at the _top_ level, try
includeFunction = #(define-void-function (filename) (string?)
(ly:parser-include-string (format "\\include ~s"
filename)))
However, depending on the context you use this in, you might get
surprised by just _when_ the inclusion happens.
> Is there a way to work around that and have includes inside functions?
>
> (The function in this case is indeed meaningless, in my real use case
> the function will hopefully construct midi files from the variables in
> the included files combined in different ways)
>
> Thanks a lot!
>
> /Leo
>
> \version "2.23.3"
>
> includeFunction = #(define-void-function (filename) (string?)
> #{ \include #filename #} )
>
> \include "includetest.ily"
>
> % \includeFunction "includetest.ily"
>
> \score { \music }
>
>
--
David Kastrup