[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SD4F: (exist? procedure-**maximum**-arity)
From: |
Blake Shaw |
Subject: |
SD4F: (exist? procedure-**maximum**-arity) |
Date: |
Wed, 29 Dec 2021 08:23:09 +0700 |
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”
- SD4F: (exist? procedure-**maximum**-arity),
Blake Shaw <=