lilypond-user
[Top][All Lists]
Advanced

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

Re: Error with default value on predicate on 2.22.0


From: Paolo Prete
Subject: Re: Error with default value on predicate on 2.22.0
Date: Tue, 12 Jan 2021 20:52:59 +0100

Thanks very much Lukas-Fabian.
This fixed all for me.
But at the same time I wonder: doesn't that API change risk to break some other code that uses the default value in the same order I used it? I think, for example, at Harm's snippets.
Not sure if it is a realistic case, but I suggest to check it.

Best,
Paolo

On Tue, Jan 12, 2021 at 8:01 PM Lukas-Fabian Moser <lfm@gmx.de> wrote:
Hi Paolo,

Am 12.01.21 um 17:01 schrieb Paolo Prete:
> Hello,
>
> I just experienced (on Linux) that this compiles with <= 2.20
>
> --------------------------------
>
> foo = #(define-music-function (parser location col staff mus)((color?
> red) string? ly:music?)
> #{ c' d' #})
>
> {
> \foo "bar" {}
> }
>
> --------------------------------
>
> But it doesn't compile with 2.22.0
> What's wrong?

Last May, Valentin (in 1ea236291f96dbe5) added the ability to use
CSS-style color names (and hex color codes, and four-number RGBA colors
with alpha channel) everywhere where previously one had to use RGB-style
colors. (I only found out about this _great_ addition by researching
your problem, so I'm actually quite happy right now.)

For this, the color? predicate had to be weakened in order to cover more
possible data types: Where previously, we had

  (define-public (color? x)
   (and (list? x)
        (= 3 (length x))
        (every number? x)
        (every (lambda (y) (<= 0 y 1)) x)))

in scm/output-lib.scm, it now reads

  (define-public (color? x)
   (or
    (string? x)
    (and (list? x)
         (let ((l (length x)))
          (or (= 3 l)
               (= 4 l)))
         (every number? x)
         (every (lambda (y) (<= 0 y 1)) x))))

To wit, while a color? used to be a list of exactly three numbers in
[0,1], now it is _either_ a string _or_ a list of three or four numbers
in the same interval.

So, in your function definition, "bar" is now a valid color?, hence is
taken as "col", and consequently LilyPond tries to read {} as a string?.
I see two solutions for your problem:

a) If you only ever need rgb colors, you could define and old-style
color? predicate and use this in your function definition.
b) You could re-order the parameters to your function in such a way that
the next predicate after the optional color? is not a sub-predicate of
color?. One example would be ly:music?, so the following works (I omit
"parser"/"location"):

\version "2.22"

foo = #(define-music-function (col mus staff) ((color? red) ly:music?
string?)
#{ c' d' #})

{
\foo {} "bar"
}

Best
Lukas


reply via email to

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