lilypond-user
[Top][All Lists]
Advanced

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

Re: elementary macro problem


From: David Kastrup
Subject: Re: elementary macro problem
Date: Fri, 21 Jul 2017 16:36:51 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

David Griffel <address@hidden> writes:

> I'm a fairly inexpert lilypond user. I've used simple macros before, but
> this one fails:
>
> thrice = \repeat unfold 3

Because there isn't a complete music expression following.

> it produces an error message:  error: unknown escaped string: `\thrice'
>
> Minimal example:
>       thrice = \repeat unfold 3
>       {\thrice {a b } }

Well, now there is a complete music expression following but it contains
"\thrice" which isn't defined yet: a hen and egg problem.

> The same thing happens if I drop the 3 and try to define rept = \repeat
> unfold.
>
> The Notation Manual 3.4.4 says "... So far we’ve seen static substitution –
> when LilyPond sees \padText, it replaces it with the stuff that we’ve
> defined it to be (ie the stuff to the right of padtext=)."
>
> It then goes on to
>
> padText =
> #(define-music-function
>      (parser location padding)
>      (number?)
>    #{
>      \once \override TextScript.padding = #padding
>    #})
>
>
> which looks more sophisticated than I need.  I just want a short
> abbreviation of \repeat unfold
> Maybe that's not possible without learning a good deal more?

It would be in the spirit of the \etc expression if you could write

thrice = \repeat unfold 3 \etc

but so far it only works on incomplete music function calls, and \repeat
isn't a music function call.  It would make perfect sense to turn it
into one, but the \alternatives syntax going with it can only be
implemented in the parser itself.

But you couldn't expect

\thrice { ... } \alternatives { ... }

to work with it then.  So with current (namely 2.19 versions), the best
you can hope to do is

thrice =
#(define-music-function (music) (ly:music?)
   #{ \repeat unfold 3 #music #})

and it still would not work in connection with \alternatives .
Basically, to give \repeat the kind of pliability that music functions
enjoy, one would need to come up with different syntax/semantics for
alternatives.

-- 
David Kastrup



reply via email to

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