From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
To: Guile User <guile-user@gnu.org>
Subject: Procedure arity and documentation
Date: Wed, 26 May 2021 19:33:28 +0000 [thread overview]
Message-ID: <42849034-24cb-912a-41b8-4e00b8bfac59@posteo.de> (raw)
Hello Guile users!
Today I found the procedure `procedure-minimum-arity`, while tab-completing in
Geiser. I then looked for its documentation in the Guile manual, but could not
find anything about it. (help procedure-minimum-arity) shows:
~~~~
scheme@(guile-user)> (help procedure-minimum-arity)
`procedure-minimum-arity' is a procedure in the (guile) module.
- Scheme Procedure: procedure-minimum-arity proc
Return the "minimum arity" of a procedure.
If the procedure has only one arity, that arity is returned as a
list of three values: the number of required arguments, the number
of optional arguments, and a boolean indicating whether or not the
procedure takes rest arguments.
For a case-lambda procedure, the arity returned is the one with the
lowest minimum number of arguments, and the highest maximum number
of arguments.
If it was not possible to determine the arity of the procedure,
`#f' is returned.
~~~~
Which helps a lot. I could not understand the procedure's output before that.
Why is the procedure named "minimum", when it also gives the number of optional
arguments and whether it accepts rest arguments?
Is this procedure official API, or is it merely exposed and I should not be
using it?
I am currently reading a book, which uses MIT/GNU Scheme and there exist
`procedure-arity-min` and `procedure-arity-max`. If there is `min`, then I would
expect `max` to be also there. I was a bit confused with Guile only having
`minimum`, but `minimum` not actually being only the minimum, but also option
and rest, which enables one to calculate the maximum.
I also found that the following errors:
~~~~
scheme@(guile-user)> (import (system vm program))
scheme@(guile-user)> (arity:nreq (program-arities (lambda (a b) (+ a b))))
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Unbound variable: program-arities
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
~~~~
Although the manual says:
> The normal case is that a procedure has one arity. For example, (lambda (x)
x), takes one required argument, and that’s it. One could access that number of
required arguments via (arity:nreq (program-arities (lambda (x) x))). Similarly,
arity:nopt gets the number of optional arguments, and arity:rest? returns a true
value if the procedure has a rest arg.
-- https://www.gnu.org/software/guile/manual/guile.html#Compiled-Procedures
Is that a bug, or is it, because I am trying to use it in the REPL and there my
procedure is not compiled?
Best regards,
Zelphir
--
repositories: https://notabug.org/ZelphirKaltstahl
next reply other threads:[~2021-05-26 19:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-26 19:33 Zelphir Kaltstahl [this message]
2021-05-27 10:23 ` Procedure arity and documentation Taylan Kammer
2021-05-27 19:23 ` Zelphir Kaltstahl
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=42849034-24cb-912a-41b8-4e00b8bfac59@posteo.de \
--to=zelphirkaltstahl@posteo.de \
--cc=guile-user@gnu.org \
/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).