From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zelphir Kaltstahl Newsgroups: gmane.lisp.guile.user Subject: Re: SD4F: (exist? procedure-**maximum**-arity) Date: Wed, 29 Dec 2021 12:49:11 +0000 Message-ID: References: <874k6stdaa.fsf@nonconstructivism.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22222"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Dec 29 13:49:58 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n2YOz-0005aO-OI for guile-user@m.gmane-mx.org; Wed, 29 Dec 2021 13:49:57 +0100 Original-Received: from localhost ([::1]:37928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n2YOy-0000P0-3d for guile-user@m.gmane-mx.org; Wed, 29 Dec 2021 07:49:56 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n2YON-0000Os-Ew for guile-user@gnu.org; Wed, 29 Dec 2021 07:49:19 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]:44099) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n2YOK-0006sM-S3 for guile-user@gnu.org; Wed, 29 Dec 2021 07:49:19 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 30518240028 for ; Wed, 29 Dec 2021 13:49:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1640782153; bh=FihaTH1m1aRdMyxmakwVniigvfSazn+7oiDaso/Lris=; h=Subject:To:From:Date:From; b=TqwB1GS0QHs6v9WI70PFPm6MEpJmw/dp3gIU86Fmh1zACd26eOK1dLVWWr41GdDDf jFri4SjTFW7ZWJD0/fByM/t49Bpl5zBhszPe3RuaDa4Ao2TPn2xWRtK5tMsTO2scWR ngftcDWnP3jVk+wYBTCbABIoczBvQEpnsDexDlt18bKstVGOQsL790fgQ/EiMxZL+G uenID95fzL7PPQkCIP+znfFC3kMiEgUyChozWX7EYJuKOIQULP7skzd3XDMWPUhP41 1WoSkvcGD7w3aTUw6TvUx2NWWPlLNj+rhi8kN2/aYi9GydZSrVNdq2i4QViZ5e9ePv nMy9D1Rxi51jw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4JPB6w4lVvz9rxG for ; Wed, 29 Dec 2021 13:49:12 +0100 (CET) In-Reply-To: <874k6stdaa.fsf@nonconstructivism.com> Content-Language: en-US Received-SPF: pass client-ip=185.67.36.65; envelope-from=zelphirkaltstahl@posteo.de; helo=mout01.posteo.de X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17929 Archived-At: 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