unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Re: SD4F: (exist? procedure-**maximum**-arity)
@ 2021-12-29 11:47 Blake Shaw
  0 siblings, 0 replies; 4+ messages in thread
From: Blake Shaw @ 2021-12-29 11:47 UTC (permalink / raw)
  To: Olivier Dion; +Cc: guile-user

Olivier Dion <olivier.dion@polymtl.ca> writes:

> Out of topic here, but what's your first impression of the book?  I was
> thinking of asking it for my birthday :-)

As someone whose introduction to scheme was sicp about a year ago, which
I spent about three months with only moving forward after solving each 
problem, getting my ass kicked every few sets of exercises (some taking
a week!) until I decided to just do a cursory overview of the rest of
the material from Chapter 4 onwards, so far SD4F has been fantastic.

So far it's a lot of the same ideas from sicp, but instead of traversing the
entire gamut of programming it's focused on one objective: explaining
how to write the most generic, composable, maintainable and reusable
software possible. So in a sense, it feels like a "refined, abbreviated,
applied sicp follow-up".

Not to say SICP isn't geared towards application of ideas, because it
absolutely is, but the first exercises don't, for example, ask that you
prove Ackermann's function. So far it sticks to the practical aspect of
software design, and has been easy to follow. As someone new to scheme
it seems like the first text I've encountered that doesn't only teach
scheme but teaches how to design software in scheme. Highly recommended!

-- 
“In girum imus nocte et consumimur igni”



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: SD4F: (exist? procedure-**maximum**-arity)
  2021-12-29  1:23 Blake Shaw
  2021-12-29  4:04 ` Olivier Dion via General Guile related discussions
@ 2021-12-29 12:49 ` Zelphir Kaltstahl
  1 sibling, 0 replies; 4+ messages in thread
From: Zelphir Kaltstahl @ 2021-12-29 12:49 UTC (permalink / raw)
  To: guile-user

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




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: SD4F: (exist? procedure-**maximum**-arity)
  2021-12-29  1:23 Blake Shaw
@ 2021-12-29  4:04 ` Olivier Dion via General Guile related discussions
  2021-12-29 12:49 ` Zelphir Kaltstahl
  1 sibling, 0 replies; 4+ messages in thread
From: Olivier Dion via General Guile related discussions @ 2021-12-29  4:04 UTC (permalink / raw)
  To: Blake Shaw, guile-user

On Wed, 29 Dec 2021, Blake Shaw <blake@nonconstructivism.com> 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:

Out of topic here, but what's your first impression of the book?  I was
thinking of asking it for my birthday :-)

-- 
Olivier Dion
Polymtl



^ permalink raw reply	[flat|nested] 4+ messages in thread

* SD4F: (exist? procedure-**maximum**-arity)
@ 2021-12-29  1:23 Blake Shaw
  2021-12-29  4:04 ` Olivier Dion via General Guile related discussions
  2021-12-29 12:49 ` Zelphir Kaltstahl
  0 siblings, 2 replies; 4+ messages in thread
From: Blake Shaw @ 2021-12-29  1:23 UTC (permalink / raw)
  To: guile-user

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”



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-29 12:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-29 11:47 SD4F: (exist? procedure-**maximum**-arity) Blake Shaw
  -- strict thread matches above, loose matches on Subject: below --
2021-12-29  1:23 Blake Shaw
2021-12-29  4:04 ` Olivier Dion via General Guile related discussions
2021-12-29 12:49 ` Zelphir Kaltstahl

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).