[Top][All Lists]

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

Re: Having trouble understanding optional and variable amount of argumen

From: Urs Liska
Subject: Re: Having trouble understanding optional and variable amount of arguments
Date: Thu, 01 Mar 2018 07:37:06 +0100
User-agent: K-9 Mail for Android

Am 1. März 2018 03:26:31 MEZ schrieb Stefano Troncaro <address@hidden>:
>Thank you! I see that this is not an option then. Also, I now
>why I couldn't make the optional arguments work, since I always left
>for last.
>Do you know if it is possible to have a flexible amount of optional
>arguments that appear before the last mandatory one? Say, for example
>(define-music-function (arg1 args music) (number? ??? ly:music?) where
>and music are mandatory, and basically everything between arg1 and the
>music expression is compacted into a list and accessed as args in the
>of the function. Not with that syntax necessarily, but something that
>allows for that kind of usage?

I *think* that's not doable in general (I'd love to be proven wrong), but if 
you can have all optional args as symbols you can use a dot-separated symbol 

What I generally use is a \with {} argument which can take arbitrary named 
arguments. In oll-core there are a few helper functions for this, especially 
context-mod->props that turns the value into a regular alist.
I've just started thinking about an enhancement that
- allows to require some arguments
- can set missing args to defaults
- allows type checking

I'd be happy to collaborate on this.

>2018-02-28 20:45 GMT-03:00 Simon Albrecht <address@hidden>:
>> On 28.02.2018 23:54, Stefano Troncaro wrote:
>>> I need a little help again. I'm struggling to understand how one
>>> make a music function like \tempo, that accepts a variable number of
>>> arguments. I couldn't find its definition so I couldn't look for
>>> So far I know about making lambdas that take additional arguments
>>> store the extras in a list, but this does not work in a music
>function (or
>>> if it works I don't know how to do it). And while I could make a
>>> that then passes the arguments to a music function, then I can't use
>>> with Lilypond syntax, so I'm forced to put the lambda and all it's
>>> arguments between parenthesis.
>>> But \tempo doesn't require parenthesis, and the parser still
>>> what is part of the function and what not. How would one go about
>writing a
>>> function that behaves like this?
>> As has been said, \tempo isn’t a music function. However, you _can_
>> functions with optional arguments; it’s mentioned in <
>> e-function-definitions>. The last optional argument has to be
>followed by
>> a mandatory argument of different type, because that’s how the parser
>> recognise that optional arguments were skipped.
>> HTH, Simon

reply via email to

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