unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
To: tomas@tuxteam.de
Cc: Guile User <guile-user@gnu.org>
Subject: Re: Applicable structs and vtables
Date: Sat, 14 Aug 2021 09:19:49 +0000	[thread overview]
Message-ID: <4f308868-fb6b-6557-76a8-1c3481983a48@posteo.de> (raw)
In-Reply-To: <20210814065316.GB11671@tuxteam.de>

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"
(https://www.gnu.org/software/guile/manual/guile.html#Compiled-Procedures
<https://www.gnu.org/software/guile/manual/guile.html#Compiled-Procedures>), but
that API is not working currently, as found out in a previous thread on this
mailing list:
https://lists.gnu.org/archive/html/guile-user/2021-05/msg00044.html
<https://lists.gnu.org/archive/html/guile-user/2021-05/msg00044.html>. 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!
Zelphir

On 8/14/21 8:53 AM, tomas@tuxteam.de 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

-- 
repositories: https://notabug.org/ZelphirKaltstahl




  reply	other threads:[~2021-08-14  9:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-13 20:33 Applicable structs and vtables Zelphir Kaltstahl
2021-08-14  6:53 ` tomas
2021-08-14  9:19   ` Zelphir Kaltstahl [this message]
2021-08-14 10:40     ` tomas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4f308868-fb6b-6557-76a8-1c3481983a48@posteo.de \
    --to=zelphirkaltstahl@posteo.de \
    --cc=guile-user@gnu.org \
    --cc=tomas@tuxteam.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).