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: Exception with multiple irritants Date: Sun, 8 Jan 2023 13:09:23 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31718"; mail-complaints-to="usenet@ciao.gmane.io" To: Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Jan 08 14:10:07 2023 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 1pEVR7-00080g-BA for guile-user@m.gmane-mx.org; Sun, 08 Jan 2023 14:10:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pEVQe-0004jI-Sr; Sun, 08 Jan 2023 08:09:39 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pEVQc-0004iv-Ij for guile-user@gnu.org; Sun, 08 Jan 2023 08:09:34 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pEVQa-0004x1-8y for guile-user@gnu.org; Sun, 08 Jan 2023 08:09:34 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id D305F240140 for ; Sun, 8 Jan 2023 14:09:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1673183367; bh=gs0ZTdSid/JgQCxy0iJicZ1D+FS4nr4ktFM3zGvQGUQ=; h=Date:Subject:From:To:From; b=c1FnoQk2F6V1B2B9dREp7tLh4qBHcmyX2/de8lbFDsb55qyktJmB7wVZWiskIJqIg /nSKIYta4PnDlJwXDe7GdL7A1oDdfBDiWipN7yKLHSfN3doHAWoliUEin+1HD/y1mn cjYK3+dXKFAwtXb5l1sUZHLutExtYguyFLk6kgvLFITw6H9sIEBBC9reQozT547VJf UTTILeoAMwPHmwAMTM7OWOdXktMd7s4OWrOLVPiD8CkdBVjC15oDTFMtXVgda3mv45 RXBY4ZYHRF4jf7o0x2zN6eLxvPREO2dqDW5kPJjr0LHZtelv3mbtY6n0W+N/L8x+FM X+HU0HRQOb/Gg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Nqcq85pN7z6tn4 for ; Sun, 8 Jan 2023 14:09:24 +0100 (CET) Content-Language: en-US In-Reply-To: Received-SPF: pass client-ip=185.67.36.66; envelope-from=zelphirkaltstahl@posteo.de; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, 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=ham 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-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:18851 Archived-At: On 11/25/22 01:03, Zelphir Kaltstahl wrote: > Hello Guile Users! > > I have a question regarding exception creation in general and maybe in > specific about irritants. > > I created a new exception type: > > ~~~~ > (library (exceptions) >   (export make-contract-violated-exception-plain >           make-exception-contract-violated-compound >           &contract-violated >           contract-violated-exception?) >   (import (except (rnrs base) let-values) >           (only (guile) >                 lambda* λ >                 record-constructor >                 make-exception-type >                 &programming-error) >           (ice-9 exceptions)) > >   ;; Create a custom exception type, to make it clearer, >   ;; that a contract failed, and not only an arbitrary >   ;; assertion. >   (define &contract-violated >     (make-exception-type >      ;; name of the new exception type >      '&contract-violated >      ;; parent exception type >      &programming-error >      ;; list of values the constructor of the exception >      ;; takes and their names in the record >      '())) > >   (define make-contract-violated-exception-plain >     ;; record-constructor is a procedure, which will return >     ;; the constructor for any record. >     (record-constructor >      ;; Create an exception type, which is a record. This >      ;; record has a constructor, which we can name using >      ;; define for example. >      &contract-violated)) > >   (define contract-violated-exception? >     (exception-predicate &contract-violated)) > >   (define make-exception-contract-violated-compound >     (λ (message origin irritants) >       (make-exception >        (make-contract-violated-exception-plain) >        (make-exception-with-message message) >        (make-exception-with-origin origin) >        (make-exception-with-irritants irritants))))) > ~~~~ > > However, I realized, when a contract is violated, it would be nice to not only > see the violated contract or condition as irritants, but also the values of > the irritants. So I simply tried adding them as well in the exception: > > ~~~~ > ... > (define make-exception-contract-violated-compound >     (λ (message origin irritants irritant-values) >       (make-exception >        (make-contract-violated-exception-plain) >        (make-exception-with-message message) >        (make-exception-with-origin origin) >        (make-exception-with-irritants irritants) >        (make-exception-with-irritants irritant-values)))) > ... > ~~~~ > > Note, that now I have 2 times `make-exception-with-irritants` in there. This > does not cause an error and `exception-irritants` still returns the first > irritants, so my tests also all still pass, as I have not tested for there not > to be other exception attributes. > > For example a violated exception example could look like this: > > ~~~~ > (define-with-contract bla >   (require (> foo 10)) >   (ensure (> 0)) >   (λ (foo) >     (- 20 foo))) > > (bla 10) > > ice-9/boot-9.scm:1685:16: In procedure raise-exception: > ERROR: >   1. &contract-violated >   2. &message: "contract violated" >   3. &origin: bla >   4. &irritants: (> foo 10) >   5. &irritants: (> 10 10) > ~~~~ > > Nice! Now I have the value of `foo` in this case as well and that could be > useful information in cases, when I get a violated contract unexpectedly. > > However, having irritants twice seems a bit weird. Is this something, that is > safe to do? Something expected and probably unchanging in future versions of > GNU Guile? Or does it merely work by chance? > > I could always make another exception type like > "exception-with-irritant-values" or something and use that, instead of a > second "with irritants" call. > > Best regards, > Zelphir Hi! Does anyone know this? Is it OK and reliable to have more than 1 `exception-with-irritant-values` in a compound exception? Regards, Zelphir -- repositories: https://notabug.org/ZelphirKaltstahl