lilypond-user
[Top][All Lists]
Advanced

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

Re: Scheme optional arguments, number-list


From: Mark Knoop
Subject: Re: Scheme optional arguments, number-list
Date: Sat, 23 Apr 2016 15:27:46 +0100

Thanks David,

At 15:01 on 23 Apr 2016, David Kastrup wrote:
>Mark Knoop <address@hidden> writes:
>> On upgrading to 2.19.32, one of my regular functions no longer works.
>> It seems that a single number as the first argument is now accepted
>> as a number-list whereas before it was not and thus became the second
>> argument.
>>
>> Whilst the new possibility to write lists as 1,2,3,4 is very nice, is
>> there any way to alter my function definition to achieve the old
>> behaviour?
>>
>> myFunction = #(define-void-function
>>   (a b c d)
>>   ((number-list? '()) number? (boolean? #t) fraction?)
>>   (print "\na=~s b=~s c=~s d=~s\n" a b c d))
>>
>> {
>>   % this works when all arguments are specified
>>   \myFunction 1,2,3,4 4 ##t 4/4
>>   % not specifying first argument no longer works
>>   \myFunction 4 4/4
>> }  
>
>You can write your own predicate that will reject lists containing a
>single number.  But it will then also reject an explicit #'(3).  I'm
>afraid that you just created an interface that was too delicate to
>survive further development.

In this instance single number lists are not relevant anyway. So I've
tried this method:

#(define (multi-number-list? x)
  (and (list? x)
       (< 1 (length x))
       (every number? x)))

testfn = #(define-void-function
  (a) (multi-number-list?)
  (print "\na=~s length=~s\n" a (length a)))

{
  % this works
  \testfn #'(1 2 3)
  % this doesn't - why?
  \testfn 1,2,3
  % this fails as expected
  \testfn 1
}

...and was surprised to see that the new list syntax doesn't work in
this instance. It's not clear to me at what point lilypond/guile
decides that something is a list or not.

So this method will work for my old scores which still use #'(1 2 3)
syntax, but can't take advantage of the new 1,2,3 syntax.

>Of course, you can always skip an optional argument using \default, but
>that's likely not what you would want to do.

Yes, still hoping to find a way to avoid that if possible.

-- 
Mark Knoop



reply via email to

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