[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: SD4F: (exist? procedure-**maximum**-arity)
From: |
Zelphir Kaltstahl |
Subject: |
Re: SD4F: (exist? procedure-**maximum**-arity) |
Date: |
Wed, 29 Dec 2021 12:49:11 +0000 |
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