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: Exception with multiple irritants Date: Fri, 25 Nov 2022 00:03:24 +0000 Message-ID: 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="24383"; mail-complaints-to="usenet@ciao.gmane.io" To: Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri Nov 25 01:04:19 2022 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 1oyMCY-000651-Rt for guile-user@m.gmane-mx.org; Fri, 25 Nov 2022 01:04:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyMBt-0007Ad-Dj; Thu, 24 Nov 2022 19:03:37 -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 1oyMBs-0007AK-4g for guile-user@gnu.org; Thu, 24 Nov 2022 19:03:36 -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 1oyMBp-0006Sr-Mt for guile-user@gnu.org; Thu, 24 Nov 2022 19:03:35 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 354D5240104 for ; Fri, 25 Nov 2022 01:03:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1669334610; bh=hhblrZve2fBCOOcKg7l9sq0KDsOFHZkze2HGoQYjWbw=; h=Date:From:To:Subject:From; b=H2nbINGwKL4IplB/VCyFKQULa+Cp4JlATuVhfoA2ax1eeFsNoDkkHgq8SRo6TKxjt rmr7L94USxbShuxAwzBSm0MU22sD5+xbz5IW8N8pOMD9ICEyXsIzFrcjLjDTfEQ5u2 xKFNXlmCztzOyPyKFIJZnanxZTRkrr37x6FYTMvXWz/opK+GwSgFww2wr/oxtjrC+E Q2YnJQwnJboYCttPPY3MaKbCGu7WSDKunEk7Y27YBzpqiCIyeMFXQvtQXkJNKXtQ4a Pubg51ZoO9sQacQIomSG6tpTRHMgsOfCsKUcqn7qh2jPBCMTrb9dLFPYmXoQRgZEWr axaTywSPvaSIw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4NJFSd2w0wz6tmr for ; Fri, 25 Nov 2022 01:03:26 +0100 (CET) Content-Language: en-US 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, HTML_MESSAGE=0.001, 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-Content-Filtered-By: Mailman/MimeDel 2.1.29 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:18749 Archived-At: 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 -- repositories:https://notabug.org/ZelphirKaltstahl