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