From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: John Cowan Newsgroups: gmane.lisp.guile.user Subject: Re: About exception handling again ... Date: Mon, 3 Aug 2020 00:41:55 -0400 Message-ID: References: <2a9a0cf9-cd7c-b118-ee01-f36d6a2e8e31@posteo.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39286"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Guile User To: Zelphir Kaltstahl Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Mon Aug 03 06:42:30 2020 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 1k2SIw-000A8S-3p for guile-user@m.gmane-mx.org; Mon, 03 Aug 2020 06:42:30 +0200 Original-Received: from localhost ([::1]:48368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k2SIv-0001ty-0b for guile-user@m.gmane-mx.org; Mon, 03 Aug 2020 00:42:29 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k2SId-0001ti-RO for guile-user@gnu.org; Mon, 03 Aug 2020 00:42:12 -0400 Original-Received: from mail-qt1-x82a.google.com ([2607:f8b0:4864:20::82a]:39960) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k2SIa-000468-Vb for guile-user@gnu.org; Mon, 03 Aug 2020 00:42:11 -0400 Original-Received: by mail-qt1-x82a.google.com with SMTP id s16so27368178qtn.7 for ; Sun, 02 Aug 2020 21:42:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ccil-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3ZVgy0s9/OdOO7PDhQCO3pAnlSdYzFVnuqkcOUoRwJ8=; b=QEfmpOJrRphN18RuFEb39AbQn51PFc6IXlfXh8l4Y2TRrIbARzq69TQQ4KKaMTc8mM 1XoBKWk2Rf8Mi54Y6Jcypqm64uva/29RM8Nvpw6cG0coTBt+maT2JglvRgP9oqLQ+bLj ldGyvTs2C+kmHnTlvHf50yptMFpePMo+c3xJj+2/lXxS10fiaWmv/8uy1XL0x0WxF/hK 3Z7+i3MpNYTe5adB5lG2w36adT5lVwQi5QdgzInZROZmZMrUnkTxAjIcSEF3P17pLAlL KLpJ1UtNC9A7ZGC+D/sVWIImtFbZTSisbIgoCsOalQru2+VqI99F8rNeRpHKsIA6R1xC sUpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3ZVgy0s9/OdOO7PDhQCO3pAnlSdYzFVnuqkcOUoRwJ8=; b=EvDv+BVPawlJaCiBVbfN2KGrbZCGyU4ERKBR4HBhzyCHBvOQ+cD/cec6DTYB8xraoY KD7hitGV6phT4yxa68v9A2BfWDmIdZZACtHd1cWMkXfswSJEZpHT5GPLLWqaVaVRhqiM 23gfmQncOvKbJPPTb7olJZYsoLd0rn1JzV0OomK9ViIIo8ElvyGZaWMhHM2SQRatJoU0 6yGVMFH+vV/rdb0XEeMMR518+o+P21GNXfj5G73EHd1YjJWLpZ1HHw4q56/th8u3JgZv KxQsEnZ/ePbarr5S90ijrPk/EAHj7x4W6FaeGnHRKCxQ5aJYPbvTYECwfV3d/yV1tmh2 t9VQ== X-Gm-Message-State: AOAM533cPO1nVe1aJdfYhkxCybGXUO5fyu83+iHO97iOoVVuIGXmFfCy 0mB3EdrSdFxzDaClLb3oGf0tKDCbHRvE3C/8edh0GQ== X-Google-Smtp-Source: ABdhPJzbob5IaVyCxmUFnSIXT0KOmzJd6uUULGskW6octvG1ERvN+E4+R5FIuxhu6gXr/y8BZXQJmcCNfG81HozHrrI= X-Received: by 2002:ac8:729a:: with SMTP id v26mr15069438qto.362.1596429726149; Sun, 02 Aug 2020 21:42:06 -0700 (PDT) In-Reply-To: <2a9a0cf9-cd7c-b118-ee01-f36d6a2e8e31@posteo.de> Received-SPF: pass client-ip=2607:f8b0:4864:20::82a; envelope-from=cowan@ccil.org; helo=mail-qt1-x82a.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 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:16770 Archived-At: On Sun, Aug 2, 2020 at 2:05 PM Zelphir Kaltstahl wrote: > 1. Is there any situation, in which one would like to raise a > non-continuable exception / condition, and not unwind the stack? Would > that make sense in any situation? > I'm going to talk about Scheme in general, not Guile specifically. There are at least three use cases: 1) A reflective low-level debugger that can examine variables in the current stack frame, which can't possibly work if the stack frame is gone. 2) A handler that wants to examine the dynamic environment in place when the exception was raised. 3) A restart system that returns to the context of the raise and executes recovery code, often chosen on the basis of interaction. Frequently used recovery actions include retrying the failed operation (on the assumption that the external environment has changed), retrying the operation with one or more different variables, and setting local variables to new values and retrying. A "Lisp debugger" is code that examines the available restarts and invokes one of them, but Scheme doesn't have such a thing yet because it has no restart system yet. See < https://github.com/johnwcowan/r7rs-work/blob/master/RestartsCowan.md>. CL has a restart system rather more complex than my proposal, which is based on an earlier proposal by Taylor Campbell. > Is this all correct? > I would say "correct but not complete". > 3. What would be a code example for a continuable exception / condition > and what does the "continuing" there look like? I think the idea of > exception in my head is still influenced a lot by Python or other > languages, where it seems like all exceptions are non-continuable. (Is > that correct?) > Let's say a procedure wants to open a configuration file, but the configuration file cannot be opened. Raising a continuable exception allows the handler to take some recovery action (perhaps it prompts the user for the location of the config file) and return to the point where the exception was raised. Restarts extend this concept by providing a protocol for the handler to communicate with the raiser, just as condition objects are a protocol to let the raiser communicate with the handler. In languages without continuable exceptions, such a retry must be done from the handler level, which may imply re-executing a lot of code that was run before the config file was wanted. With continuable exceptions, this is not necessary. The `guard` special form basically emulates the behavior of {Python, JS, Java, C#} style exception systems in cases where that behavior is sufficient. > 4. Is there a situation, where one would like to raise a continuable > exception / condition, but also unwind the stack? > Not that I can think of. > IWhat does it mean for with-exception-handler to "return"? How can it not > return? Does this mean CPS like not returning, or does it mean "not > return a value"? > The former. An exception being raised non-continuably is really raised continuably, but then if that returns, an exception that means "attempt to continue from a non-continuable exception" is raised non-continuably. If you aren't careful in your handler to re-raise exceptions you don't understand (normally with raise-continuable), this will obviously get into an infinite loop. (In CL the behavior of a handler is slightly different. If it returns, the exception is re-raised automatically. so in order to unwind the stack one must use one of CL's three upward continuations: block/return, tagbody/go, or catch/throw. The last is dynamically scoped, so it is usually the thing to do in this context. Handler-bind, like guard, is a convenience macro for emulating stack-unwonding systems._ John Cowan http://vrici.lojban.org/~cowan cowan@ccil.org He that would foil me must use such weapons as I do, for I have not fed my readers with straw, neither will I be confuted with stubble. --Thomas Vaughan (1650)