lilypond-user
[Top][All Lists]
Advanced

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

Multiple optional arguments


From: Urs Liska
Subject: Multiple optional arguments
Date: Thu, 10 Nov 2016 12:43:15 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0

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.

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




reply via email to

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