From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
To: guile-user@gnu.org
Subject: Re: SD4F: (exist? procedure-**maximum**-arity)
Date: Wed, 29 Dec 2021 12:49:11 +0000 [thread overview]
Message-ID: <a21a3cd4-f434-5a3e-71c6-81474ed821c9@posteo.de> (raw)
In-Reply-To: <874k6stdaa.fsf@nonconstructivism.com>
Hello Blake!
You might be interested in this:
https://notabug.org/ZelphirKaltstahl/function-combinators/src/master/notes.org =)
Although I did try to implement things in a purely functional way, going perhaps
a bit too far.
Also "applicable structs" in Guile could prove useful, if you can find any
usable example and are able to adapt to the use-case.
Regards,
Zelphir
On 12/29/21 2:23 AM, Blake Shaw wrote:
> 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
>
--
repositories: https://notabug.org/ZelphirKaltstahl
next prev parent reply other threads:[~2021-12-29 12:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-29 1:23 SD4F: (exist? procedure-**maximum**-arity) Blake Shaw
2021-12-29 4:04 ` Olivier Dion via General Guile related discussions
2021-12-29 12:49 ` Zelphir Kaltstahl [this message]
-- 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=a21a3cd4-f434-5a3e-71c6-81474ed821c9@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).