On 19/06/2025 17:27, Valentin Petzel wrote:
Hello Pondmates!

In Lilypond we have this wonderful but weird sugar function `grob-
transformer`. While this thing is nice it is also a bit awkward. For one thing
it requires specification of *what* is transformed (for else it does not know
that information. For another thing it adds a lot of scheme boilerplate,
making score less transparent.

I’ve been thinking we could quite simply facilitate usuage by wrapping this in
a music function like this:

%%%
transform =
#(define-music-function (path proc)
    (symbol-list? procedure?)
    #{
      \override #path =
      #(grob-transformer (last path) proc)
    #})
%%%

This will more or less mirror the interface of `\override path = callback` by
a `\transform path transformer`. This way we can nicely write something like
this:

%%%
{
   \temporary\transform NoteHead.stencil
   #(lambda (grob orig) (ly:stencil-in-color orig "red"))
   \temporary\transform NoteHead.stencil
   #(lambda (grob orig) (ly:stencil-scale orig 2 2))
   4 4 4 4
}
%%%

which I think is much more concise than

%%%
{
   \temporary\override NoteHead.stencil =
   #(grob-transformer
     'stencil
     (lambda (grob orig) (ly:stencil-in-color orig "red")))
   \temporary\override NoteHead.stencil =
   #(grob-transformer
     'stencil
     (lambda (grob orig) (ly:stencil-scale orig 2 2)))
   4 4 4 4
}
%%%

and would thus make using this feature more accessible and scores nicer to
look at.

So I would like to ask what is your take, and if we maybe should include such
an interface into Lilypond.

Cheers,
Tina

Speaking as a programmer of 60 years experience, lambdas give me the willies - and I started with Jensen's Device in Algol60 when Algol60 was new.

Yes, lambdas are neat, but IMO they tend to be unreadable and unmaintainable. If you like them, use them; but do not make them a requirement, particularly for those who are not programmers.


Reply via email to