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: Lukas-Fabian Moser
Subject: Re: Error with default value on predicate on 2.22.0
Date: Tue, 12 Jan 2021 20:01:25 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

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]