lilypond-user
[Top][All Lists]
Advanced

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

Re: Multiple optional arguments


From: Richard Shann
Subject: Re: Multiple optional arguments
Date: Thu, 10 Nov 2016 12:10:03 +0000

On Thu, 2016-11-10 at 12:43 +0100, Urs Liska wrote:
> Hi all,
> 
> I would like to have two optional arguments in a music function. My
> current approach fails, and I don't know if I'm doing anything wrong or
> if I'm trying the wrong thing in the first place.
> 
> I have created an interface with two optional and one mandatory
> argument. I thought that this should work as long as they differ in
> type. However, it only works properly when both arguments are missing or
> if the second arg is missing (and of course if all are provided).
> However, when the first one is missing the function raises a syntax error.

I think what you need to do is to make the type test for the first one
to be something like (lambda (a) (or (type1? a) (type2? a))) and then
check which type you actually got inside the function body.

Richard


> 
> Is this because LilyPond can't properly discern the two types or is it
> generally impossible to use two such optional arguments in sequence? And
> if the latter, how can I achieve the effect otherwise? What I want is
> that the function uses a global variable but sets it to a new value
> before in the case one is provided by the user.
> 
> Thanks
> Urs
> 
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> 
> \version "2.19.50"
> 
> test =
> #(define-void-function (fund dur ratio)
>    ((ly:pitch?) (ly:duration?) fraction?)
>    (if (ly:pitch? fund)
>        (format "Pitch found: ~a" fund))
>    (display fund)(newline)
>    (display dur)(newline)
>    (display ratio)(newline))
> 
> 
> % regular invocation
> \test b, 4 3/2
> 
> % both optional args missing (works)
> \test 4/3
> 
> % second optional arg missing (works)
> \test b, 5/4
> 
> % first optional arg missing (syntax error: unexpected FRACTION)
> \test 2 6/5
> 
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> 
> 
> _______________________________________________
> lilypond-user mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/lilypond-user





reply via email to

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