[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Optional arguments
From: |
David Kastrup |
Subject: |
Re: Optional arguments |
Date: |
Fri, 07 Mar 2014 07:03:06 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Paul Morris <address@hidden> writes:
> David Kastrup wrote
>> The last argument of a function is never "really" optional (the only way
>> to get the default value is by writing \default).
>>
>>> Relevant docs:
>>> http://lilypond.org/doc/v2.19/Documentation/extending/scheme-function-definitions
>>
>> The next one tells the story about optional arguments:
>> <URL:http://lilypond.org/doc/v2.19/Documentation/extending/scheme-function-usage>
>
> Ok, thanks, I see how it works now.
>
> So if I understand this[1] correctly... then the way that LilyPond knows an
> optional argument is being omitted is by getting an argument of a different
> type in place of that optional argument (e.g. a string rather than a
> number). An optional argument has to be followed by an argument of a
> different type for things to work when it is omitted.
Or be skipped using \default.
> It clearly won't work if you have two argument of the same type in a
> row and try to omit the first one as optional. (And there's also the
> case of omitting several optional arguments in a row...)
>
> [1] "Once an optional argument predicate does not match an argument,
> LilyPond skips this and all following optional arguments, replacing them
> with their specified default, and ‘backs up’ the argument that did not match
> to the place of the next mandatory argument. Since the backed up argument
> needs to go somewhere, optional arguments are not actually considered
> optional unless followed by a mandatory argument."
The "once one optional argument is skipped" semantics was required to
get things like \key and \mark work in a sensible manner when converted
to functions from builtin syntax constructs.
--
David Kastrup