Hello David, there is some confusing going on here about how certain things are evaluated. When you do
{ ... something ... } this is evaluated pretty much as it is parsed, returning some music object. So \keepWithTag #'textI \tag #'textII { #(define l "B") } this will first evaluate the expression { #(define l "B") } which returns an empty music object and as side effect sets a variable, then it will call \tag upon that music, and then call \keepWithTag on that Music. What you intend to do is in fact not possible with \tag. What you want to do is to delay the evaluation until the point where you have the information to make this decision. This can be done using a music function: \version "2.24.1" #(define l '()) musicfn = #(define-music-function (tag) (symbol?) #{ #(if (equal? tag 'textI) (set! l "A")) #(if (equal? tag 'textII) (set! l "B")) c''1^\markup\l #(if (equal? tag 'textI) (set! l "C")) #(if (equal? tag 'textII) (set! l "D")) c''1^\markup\l #}) \musicfn textI \musicfn textII Note that here it is necessary to first create the global binding using #(define ...) and then use (set! ...) to change that binding. Cheers, Valentin Am Mittwoch, 17. Mai 2023, 21:58:49 CEST schrieb dfro: > I want to define and change variables mid-stream in a music expression, > while also using tags. Below is an example of what I am trying; but, it > does not work. > > > \version "2.24.1" > > \keepWithTag #'textI > %\keepWithTag #'textII > > > { > \tag #'textI { #(define l "A") } > \tag #'textII { #(define l "B") } > c''1 ^\markup \l > \tag #'textI { #(define l "C") } > \tag #'textII { #(define l "D") } > c''1 ^\markup \l > } > > > The tags are not keeping lilypond from skipping the define's that are in > \tag #'textII. Is there a way to make this work? > > Is there a way to define variables using lilypond syntax inside a music > expression? > > > Peace, > > David
signature.asc
Description: This is a digitally signed message part.