lilypond-user
[Top][All Lists]
Advanced

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

Re: \include inside function


From: Jean Abou Samra
Subject: Re: \include inside function
Date: Tue, 1 Feb 2022 23:14:52 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0

Le 01/02/2022 à 20:10, Valentin Petzel a écrit :
Hello David,

An assignment basically adds a pair (symbol, value) to some assignment table.
So shouldn’t it be possible to parse a file with a new assignment table and
then convert this assignment table into a scheme accessible structure?

I do not mean to say that assignments should not be performed, but that they
should be performed in a different scope, which we then make accessible from
the original scope.

This could also enable some sort of name-spacing. Let’s say we have different
Ly files that were not written with name-spacing in mind and then we want to do
a project to combine these. Then instead of needing to rename assignment in
one file we could do something like

fileA = \include "fileA.ly"
\fileA.score

or something, whatever.


Well, if you are ready to get evil, you can do

\version "2.23.5"

includeNamespace =
#(define-scheme-function (filename) (string?)
   (let ((new-parser (ly:parser-clone)))
     (ly:parser-parse-string
      new-parser
      (format #f "\\include ~s" filename))
     (define-music-function (name) (symbol?)
       (with-fluid* (@@ (lily) %parser)
                    new-parser
                    (lambda ()
                      (ly:parser-lookup name))))))

tmp = \includeNamespace "/home/jean/tmp/tmp.ly"

{ \tmp var }


For some reason that I don't have the time to figure
out, this requires a development version.

Jean




reply via email to

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