[Top][All Lists]

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

Re: Applicable structs and vtables

From: Zelphir Kaltstahl
Subject: Re: Applicable structs and vtables
Date: Sat, 14 Aug 2021 09:19:49 +0000

Hi Tomas!

Ultimately I need the minimum and maximum arity of functions (not sure if
anything in between is needed, but I think not). Minimum and knowing, that rest
arguments exist is not sufficient. The exact maximum number of arguments is what
I require, even if it turns out to be infinity or some implementation limit.

Trying to give an example:

It is a learning project, about function combinators and there are combinators,
which could for example return functions, which split their arguments into 2
groups of arguments, 1 group for each combined function. Lets say the combined
function h takes k, k+1 or k+2 arguments. Out of k arguments the first function
(f) of the combined functions could take n arguments leaving k-n arguments for
the second function (g). However, if k+1 arguments were provided to h or k+2
arguments, then then the second function (g) could take k-n+1 or k-n+2
arguments, simply because more arguments are remaining for the second function.

To implement checks for correct number of arguments at runtime (assertions), I
need, I think, the exact maximum number of arguments and not only the
information, that there can be rest arguments.

The reference manual has more about "program arities"
<>), but
that API is not working currently, as found out in a previous thread on this
mailing list:
<>. I think
only the one function you mention is currently working.

While that API is not properly working, I think "callable objects" could be a
solution to my problem.

Thanks for your reply!

On 8/14/21 8:53 AM, wrote:
> On Fri, Aug 13, 2021 at 08:33:33PM +0000, Zelphir Kaltstahl wrote:
>> Hi Guile users,
>> I have some code, in which I wrap procedures in a record, which contains
>> members, which express the arity of the procedures. For example one struct 
>> be:
>> <arity-function: min: 1, max: 3, function: (some lambda here)>
> I don't know whether what you're after is about generalising what a
> function can be ("callable objects" or similar), or if procedure
> arity introspection at run time is your ultimate goal.
> In the second case, there is `procedure-minimum-arity', which might
> already cater to your wishes :-)
>   (procedure-minimum-arity cons) ; takes two arguments, no "rest"
>   => (2 0 #f)
>   (procedure-minimum-arity +) ; takes at least 0, takes "rest"
>   => (0 2 #t)
>   (let ((foo (lambda (x y . z) ('some-result)))) ; DIY
>     (procedure-minimum-arity foo))               ; at least 2, with "rest"
>   => (2 0 #t)
> I don't know (yet) what the middle number is for, though ;-)
> Cheers
>  - t


reply via email to

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