lilypond-user
[Top][All Lists]
Advanced

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

Re: Optional args in event-function not working with 2.17.6 ?


From: Thomas Morley
Subject: Re: Optional args in event-function not working with 2.17.6 ?
Date: Mon, 12 Nov 2012 03:14:26 +0100

2012/11/9 David Kastrup <address@hidden>:
> Thomas Morley <address@hidden> writes:
>
>> I was working on
>> http://lists.gnu.org/archive/html/lilypond-user/2012-11/msg00185.html
>> and wrote a event-function as a template for custom-script-signs.
>> This function uses some optional arguments and works as expected in 2.16.0
>> But not in 2.17.6
>> What am I missing?
>>
>> newScript =
>> #(define-event-function (parser location lst scaling strg) ((list? '(0
>> 0 0)) (boolean? #f) string?)
>>
>> grave = \newScript #'(-1 0 0) ##t "`"
>> acute = \newScript #'(0 1 0) ##t "´"
>> threePoints = \newScript "…"
>> noName = \newScript "@"
>
> I'd have expected these use cases to work.  However, the interface is a
> bit shaky since a string that can be parsed as a symbol will be
> converted into a list of symbols.  So a string like "a" or "xxx" would
> fit the list? predicate.  How do we get out here?
>
> a) The obvious solution is to use number-list? rather than list? as a
>    predicate, and we won't get fed a symbol list.
>
> But the behavior is unexpected, so it might be better to amend it in
> addition.  How to amend it?
>
> b) "…" does not really look like an identifier even though it obeys
> LilyPond's rules for unquoted word syntax.  Only allow ASCII characters
> in things auto-converted into symbol lists.
>
> c) That does not help with "xxx".  Only allow unquoted words to
> autoconvert into symbol lists.  I am actually working on this already
> since I am not satisfied with input/regression/lyric-tweak.ly (writing
> quotes seems like it should be sufficient; having to write \markup seems
> weird).  But I am not finished yet, and it would have warranted getting
> finished before discussion.  I have kept the "changes.tely" entry vague
> enough that it would cover this behavior as well.  Cough cough.
>
> Solution c would make quoted and unquoted strings unequivalent.
> Solution b would stop the equivalence between what can be an unquoted
> word and what can be a symbol.
>
> I am not decided about b.  It would not have helped you much.  You'd
> still have gotten failures, but the problem would likely have been
> easier to recognize.  Possibly with both b and c in place, it would
> become easy to guess what happened in the remaining failure cases.
>
> What do you think?
>
> --
> David Kastrup

Hi David,

sorry replying that late.

a)
My initial function works following your suggestion to use number-list?
or
if changing the string?-predicate to markup? and using \markup "xxx",
with the function-call.
That's nice.
Thanks a lot.

b)
I can't follow all subtleties of your explanations. And also, I can't
imagine all consequences of possible code-changes.
The following is the code I used for testing some alternatives.

\version "2.17.6"

#(define (command l n t)
#{
        \once \override NoteHead #'after-line-breaking =
          #(lambda (grob)
            (ly:grob-set-property! grob 'stencil
               (grob-interpret-markup grob (markup t)))
            (ly:grob-set-property! grob 'font-size n)
            (ly:grob-set-property! grob 'color l))
        \once \override  Score.TimeSignature #'stencil = ##f
#})

aa =
#(define-music-function (parser location lst size txt)((list? '(1 0
0)) (number? 1) markup?)
(command lst size txt))

bb =
#(define-music-function (parser location lst size txt)((number-list?
'(1 0 0)) (number? 1) string?)
(command lst size txt))

% --- test
\paper { line-width = 30 indent = 0 }

\relative c'' {
        \aa #'(0 1 1) #1 \markup "xy"
        c1
        \aa \markup "xy"
        d
        % error with (omitting the first argument):
%        \aa #3 \markup "xy"
%        e
        \break
        \bb #'(0 1 1) #1 "xy"
        c
        \bb "xy"
        d
        % error with (omitting the first argument):
%        \bb #4 "xy"
%        e
}

Seems to work with both functions.
I'd prefer \bb
i.e using number-list? because in the end it's less typing.
But I'd be happy with both versions.

c)
The functions above are using two optional arguments.
And I'm able to omit both optional arguments or the second.
But I can't omit only the first.
Why?


Regards,
  Harm



reply via email to

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