Thomas Morley <thomasmorle...@gmail.com> writes:

> 2016-07-01 0:05 GMT+02:00 Br. Gabriel-Marie | SSPX <brgabr...@sspx.org>:
>> Thanks, Mr. Meyn,
>>
>> That certainly does the trick.
>>
>> So you can't write macros for \with{} statements?
>> Why couldn't I do it this way, if I just want to create the \with statement?
>
> Obviously a call of a scheme-function is not allowed instead of a
> \with-expression, opposed to a static value stored in vavariable:
>
> \version "2.19.44"
>
> %% fails:
> tstI =
> #(define-scheme-function ()()
> #{ \with { instrumentName = "foo" shortInstrumentName = "foo" } #})
> \new Staff \tstI { r1 }
>
> %% works:
> tstII =
> \with { instrumentName = "foo" shortInstrumentName = "foo" }
> \new Staff \tstII { r1 }

Issue 4911 is supposed to harmonize this by stopping the second example
from working.  This makes it possible to recognize the syntax without
knowing the type of \tstII in advance (could be a music expression,
leading to completely different structure).

> There are other possibilities, though:
>
> \version "2.19.44"
>
> %% (1)
> #(define (foo nmbr)
> #{
>     \with {
>       instrumentName = #(format #f "~a." nmbr)
>       shortInstrumentName = #(format #f "~a." nmbr)
>     }
> #})
>
> \new Staff $(foo 1) { r1 }

Will also stop working.

> %%(2)
> buzz =
> #(define-scheme-function (nmbr)(number?)
> #{
>     \with {
>       instrumentName = #(format #f "~a." nmbr)
>       shortInstrumentName = #(format #f "~a." nmbr)
>     }
> #})
> \new Staff \with { \buzz #2 } { r1 }

\new Staff \with \buzz #2 { r1 }

is also possible.


> %%(3)
> #(define (set-instrument-names-to-number-string nmbr mus)
>         (if (eq? (ly:music-property mus 'name) 'ContextSpeccedMusic)
>             (ly:music-set-property! mus 'property-operations
>               (list
>                 (list
>                   'assign
>                   'instrumentName
>                   (format #f "~a." nmbr))
>                 (list
>                   'assign
>                   'shortInstrumentName
>                   (format #f "~a." nmbr))))
>               mus)
>             mus)
>
> tst =
> #(define-music-function (nmbr mus)(number? ly:music?)
> (set-instrument-names-to-number-string nmbr mus))
>
> \tst #3 \new Staff { r1 }

Hm.  At the current point of time, destructuring expression requires
Scheme programming.  And absorbing \new Staff into \tst #3 makes things
much less flexible (\context Staff = "..." just becomes impossible
then).  Don't really like that approach, even though stuff like \once,
\temporary and a few others have been implemented in that manner.

-- 
David Kastrup

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to