lilypond-user
[Top][All Lists]
Advanced

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

Re: Copy variable by value in a current-module.


From: Robert Kubosz
Subject: Re: Copy variable by value in a current-module.
Date: Sat, 16 Oct 2021 14:58:56 +0200

Thanks for quick answers, Jean and David! The function "ly:music-deep-copy" is the solution I was looking for :-)

> module-ref and module-set! are useful for dealing with variables of which the name is not known in advance.
Actually, in my case I don't know in advance the name of a variable which value I want to copy, that's why I used the module-ref function. In the example presented to you I used a symbol, because I wanted to keep the example as simple as possible.

> It assumes that the #{ c' des' #} part comes from something programmatically,
Yes, that's the reason.

> The other way is to use ly:music-deep-copy and it's not like this isn't mentioned in the "LilyPond — Extending" guide of LilyPond
You know, David, I just got lost. I wish I had more time to work with my project.

Many many thanks!
Robert

sob., 16 paź 2021 o 12:14 David Kastrup <dak@gnu.org> napisał(a):
Robert Kubosz <kubosz.robert@gmail.com> writes:

> I want to make a copy of a variable defined in a separate file, but run in
> the same current-module.
> The copy I make is a copy-by-reference, and in result any modifications I
> apply to the copy also appear in the original.
> How do I make a copy-by-value in a current-module?
>
> More detailed example is attached to this email.
>
> Thanks in advance!
> Robert

Well, one thing to note is that LilyPond's "contract" is that you only
work with copies of music.  That is why something like

\trumpet-first

actually delivers a _copy_ of trumpet-first rather than the original.
Commands like \transpose then feel free to change their input as it is
either a mere copy or does not exist elsewhere under a different name.

So when you do Scheme programming, you need to work with copies.  The
easiest way, of course, is not to access variables directly but only
write music functions processing their input.

Since you can deliver this input in LilyPond mainly using \... it
automatically is either a copy or an original _expression_ not used
elsewhere.

The other way is to use ly:music-deep-copy and it's not like this isn't
mentioned in the "LilyPond — Extending" guide of LilyPond.

--
David Kastrup

reply via email to

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