David,

Why does this have to be a list?  Why not just make it two separate
> arguments?
>
> If, for whatever reason, you really really really have this information
> in a two-element list called whatever, you can still write
>
> \once \alterBroken "Staff.BarLine" #'color #@whatever
>
>
It certainly makes sense to use multiple arguments instead of a list for a
music function that applies an override to a breakable item like a clef,
since there are only two pieces to consider.  However, the function is
designed to apply to spanners as well, and these of course may have more
than two pieces (e.g., SystemStartBar).  I know it’s possible to have music
functions with optional arguments, but are they able to accept an
indeterminate number of arguments, one for each potential spanner sibling?

Regarding optional arguments:  I’ve been experimenting, and I’ve hit
several stumbling blocks.  In the following (very contrived) example, I
expect that both key signatures will be green.  Both are when all arguments
are present.  When the optional argument is omitted, both should again be
green because (scheme? arg2) still returns #t.  Instead, both key
signatures disappear.  I don’t understand this behavior.

test =
#(define-music-function (parser location property arg1 arg2)
  (symbol? scheme? (scheme?))
  (display (scheme? arg2)) ; returns #t even if arg2 omitted
  #{
    \once \override Staff.KeySignature $property =
      #(lambda (grob)
        (if (eq? (ly:item-break-dir grob) LEFT)
            arg1
            (if (scheme? arg2) arg1)))
  #})

{
  c''1
  \break
  \test #'color #green #red
  %% key signatures disappear if following line used:
  %\test #'color #green
  \key cis \major
  cis''
}

My second quandary is the fact that (scheme? arg2) returns #t when arg2 is
omitted, so it appears useless as a criterion for whether an optional
argument is there or not..  (I’ve chosen scheme? as my predicate so the
generalized function can accept a wide variety of data types.)

Am I doing something wrong here?  Any guidance you could give me would be
much appreciated.

-David
_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to