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: Thomas Morley
Subject: Re: Scheme optional arguments, number-list
Date: Sat, 23 Apr 2016 17:58:14 +0200

2016-04-23 16:27 GMT+02:00 Mark Knoop <address@hidden>:
> 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.

A probably related observation:

\version "2.19.40"

my-time =
#(define-music-function (v1 v2)(scheme? scheme?)
  #{ \time $v1 $v2 #})

%% works
{
  %% default with comma-separated list
  \time 2,2,1 5/8
  g'8 8 8 8 8
  %% or
  \time 1,1,2,1 5/8
  g'8 8 8 8 8
}

%% works
{
  %% \time redefined with common-list
  \my-time #'(2 2 1) 5/8
  g'8 8 8 8 8
  %% or
  \my-time #'(1 1 2 1) 5/8
  g'8 8 8 8 8
}

%% doesn't work
{
  %% \time redefined with comma-separated list
  \my-time 2,2,1 5/8
  g'8 8 8 8 8
  %% or
  \my-time 1,1,2,1 5/8
  g'8 8 8 8 8
}

A problem with the function-macros?


Cheers,
  Harm



reply via email to

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