From: Blake Shaw <blake@nonconstructivism.com>
To: guile-user@gnu.org
Subject: SD4F: (exist? procedure-**maximum**-arity)
Date: Wed, 29 Dec 2021 08:23:09 +0700 [thread overview]
Message-ID: <874k6stdaa.fsf@nonconstructivism.com> (raw)
Hiya Guilers,
I've just started Sussman & Hanson's new book "Software Design for Flexibility" and am trying to translate one of the functions from MIT-Scheme to Guile:
#+BEGIN_SRC scheme
(define (get-arity proc)
(or (hash-table-ref/default arity-table proc #f)
(let ((a (procedure-arity proc))) ;arity not in table
(assert (eqv? (procedure-arity-min a)
(procedure-arity-max a)))
(procedure-arity-min a))))
(define arity-table (make-weak-key-hash-table))
#+END_SRC
So far this has lead me to these associations:
|------------------------------+--------------------------+-------------------------|
| MIT | Guile | Comments |
|------------------------------+--------------------------+-------------------------|
| procedure-arity | arity | |
|------------------------------+--------------------------+-------------------------|
| hash-table-set! | hashq-set! | possibly =hash-set!= |
|------------------------------+--------------------------+-------------------------|
| hash-table-ref/default | hashq-ref | possibly =hash-ref= |
| | | or =hash-get-handle= |
|------------------------------+--------------------------+-------------------------|
| make-key-weak-eqv-hash-table | make-weak-key-hash-table | ∃(module) w/eqv-hash? |
| | | think I saw it before |
|------------------------------+--------------------------+-------------------------|
| assert | assert | in (rnrs base) |
| | &assertion | + (ice-9 exceptions) |
| | assert-macro | + in (debugging assert) |
|------------------------------+--------------------------+-------------------------|
| procedure-arity-min | procedure-minimum-arity | |
resulting in this translation of the function:
#+BEGIN_SRC scheme
(define (get-arity proc)
(or (hashq-ref arity-table proc #f)
(let ((a (arity proc)))
(assert (eqv? (procedure-minimum-arity a)
(**procedure-minimum-arity** a)))
(procedure-minimum-arity a))))
#+END_SRC
So now I'm just left with figuring out a function for getting the **maximum**[1] arity of a procedure, but I'm unsure how to go about this.
I'm a sorta-new schemer and a very new guiler, so I'm unsure where to look... any advice would be appreciated![2]
Thanks & happy hacking,
Blake
[1] double earmuffs to emphasize its a function I need but dont have
[2] there is this inquiry already posted, but there was no conclusion https://mail.gnu.org/archive/html/guile-user/2021-05/msg00044.html
--
“In girum imus nocte et consumimur igni”
next reply other threads:[~2021-12-29 1:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-29 1:23 Blake Shaw [this message]
2021-12-29 4:04 ` SD4F: (exist? procedure-**maximum**-arity) Olivier Dion via General Guile related discussions
2021-12-29 12:49 ` Zelphir Kaltstahl
-- strict thread matches above, loose matches on Subject: below --
2021-12-29 11:47 Blake Shaw
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=874k6stdaa.fsf@nonconstructivism.com \
--to=blake@nonconstructivism.com \
--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).