lilypond-user
[Top][All Lists]
Advanced

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

Re: tiny function


From: David Kastrup
Subject: Re: tiny function
Date: Fri, 01 Jul 2016 07:05:36 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

Thomas Morley <address@hidden> writes:

> 2016-07-01 0:05 GMT+02:00 Br. Gabriel-Marie | SSPX <address@hidden>:
>> 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



reply via email to

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