[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Optional arguments of a music-function?
From: |
Thomas Morley |
Subject: |
Re: Optional arguments of a music-function? |
Date: |
Tue, 17 Jul 2012 22:18:36 +0200 |
2012/7/17 David Kastrup <address@hidden>:
> Thomas Morley <address@hidden> writes:
>
>> Hi,
>>
>> I tried to adapt the syntax-trickery David showed with the new
>> \tweak-definition to an own function.
>>
>> Trying a code like the tiny example below fails.
>>
>> proc =
>> #(define-music-function (parser location name arg)((string?) ly:music?)
>> (if name
>> #{ \once \override $name #'color = #red $arg #}
>> #{ \parenthesize $arg #}))
>>
>> \relative c' {
>> c1
>> \proc "NoteHead" c
>> \proc c
>> }
>>
>> Obviously I did sth wrong.
>
> Not obviously. Unobviously, however, we have the situation that
> optional arguments can only be properly checked by the parser when they
> can be parsed without lookahead, namely are a "closed" expression, since
> only then the parser can push the value back onto its token stack: if it
> has already looked at a lookahead token, it does not have this option
> since the parser state already depends on the value of the lookahead
> token.
>
> A pitch can't be parsed without lookahead since it may be followed by
> ''' and/or ,,, and so lookahead is needed to make the decision. On the
> other hand, we have other situations where the user is not supposed to
> change the meaning of a predicate when its _value_ rather than its type
> changes, so a predicate that fails or succeeds depending on the _octave_
> of a pitch, or on the presence of a postevent or similar, is not kosher
> anyway.
>
>> Well, I could do:
>>
>> #(define-public (string-or-music? x)
>> (or (string? x) (ly:music? x)))
>>
>> procII =
>> #(define-music-function (parser location arg)(string-or-music?)
>> (if (string? arg)
>> #{ \once \override $arg #'color = #red #}
>> #{ \parenthesize $arg #}))
>>
>> \relative c' {
>> c1
>> \procII "NoteHead" c
>> \procII c
>> }
>>
>> But I'd prefer the first version.
>> How to do?
>
> Wait a few days.
>
> It's the same problem as with
> <URL:http://code.google.com/p/lilypond/issues/detail?id=2067#c19>, and
> the idea to look at the pitch identifier only at first (rather than the
> whole pitch) did occur to me only now. It is conceivable that I can
> rein this in.
>
> Until I do, the syntactical possibilities for a music argument following
> an optional argument are restricted. You can always remove the
> restriction by explicitly turning this into one lookahead-free token,
> say with
>
> \procII ##{ c4 #}
>
> but this is not really pretty.
>
> --
> David Kastrup
>
>
> _______________________________________________
> lilypond-devel mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/lilypond-devel
Can't say that I understood your explanations in all details.
But I'm sure I can wait a few days.
Thanks,
Harm