Jack Brennen on Mon, 25 Feb 2019 16:33:19 +0100

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

Re: Getting arity of closures

It would seem to me that this should work:

? install("closure_arity","lG")

That should make the internal closure_arity() function available at the GP level.

? install("closure_arity","lG")
? hypot(a,b)=sqrt(a*a+b*b)
%1 = (a,b)->sqrt(a*a+b*b)
? closure_arity(hypot)
%2 = 2
? hypot4(a,b,c,d)=sqrt(a*a+b*b+c*c+d*d)
%3 = (a,b,c,d)->sqrt(a*a+b*b+c*c+d*d)
? closure_arity(hypot4)
%4 = 4

On 2/25/19 9:46 AM, Jeroen Demeyer wrote:
Is there any GP function to determine the arity of a closure? Something like that would be useful, for example to specify different behaviour when taking a closure as input (like lfuncreate for example).