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: "Missing" libraries/concepts found in other languages/ecosystems? Date: Sun, 12 Jul 2020 22:33:22 +0200 Message-ID: References: <20200710112109.b2ffa630699452541835924b@gmail.com> <14a24bd8-2664-c7bf-eff8-ca3f4e068ef8@posteo.de> <20200711111359.acacd7d4a6b328bab44ba11e@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16483"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 Cc: Guile User To: Catonano , Chris Vine Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Jul 12 22:33:43 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 1juifP-0004C5-1V for guile-user@m.gmane-mx.org; Sun, 12 Jul 2020 22:33:43 +0200 Original-Received: from localhost ([::1]:41234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1juifO-0003XO-1r for guile-user@m.gmane-mx.org; Sun, 12 Jul 2020 16:33:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1juifC-0003X2-SP for guile-user@gnu.org; Sun, 12 Jul 2020 16:33:30 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:44709) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1juif9-0006YH-03 for guile-user@gnu.org; Sun, 12 Jul 2020 16:33:30 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id CD9B72400FD for ; Sun, 12 Jul 2020 22:33:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1594586003; bh=+eJxdOPZV8bEezHZ4tmpuwFLnWAnnXcybZLADb2v6m8=; h=To:Cc:From:Autocrypt:Subject:Date:From; b=jkYyROqtqkm/gzg4/bo3aPch4yUMOBMbJz5jmHxPQU3+4scxObx+yfrImTkgLwc83 KZ1j4lGvdh+pb4WEP92VVtmVlYiSGd0LJo/uq8WCLUsSDSx/lGzlX+RSStWoFgRDvV rTL1pNXPpuE9VwzVMjXxFbjE/Nm857bxx0F+aaVROnJhOc9ZGfnQG5HjUTCGdhlI2r eQwyP9X1wB8o8iGtKd/WlZHxys9y2qDiKbUcsm/yXDlyPHTL2kcwwDudXk+LmWpwTx AlwG0uE2lKVYJnLPNhPiCVq5b7/mGlanboxHrQmhJExF12mgiJBsYHOjzjyJ63W3Hk NGNl7AvWxrjGA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4B4dlR0SFlz6tms; Sun, 12 Jul 2020 22:33:22 +0200 (CEST) Autocrypt: addr=hwroitzsch@posteo.net; prefer-encrypt=mutual; keydata= xsFNBF3RPUYBEADWxyXN1cuFxb1XSdrZ6lZ8VlBfD8pYY7oWAAmvjBv4GUAMwMkRYQBPIPFs sRbJC1hGH0qgDN2HhgFQaGEkd0HxLzXiMHvOb9W87i2UyKjZOi8+3weoumcYj5PL9CMj/868 kj2sR9Uu7ovGelbFHZqd4elTZu+DEA/VECsIErewMs9hPA5UuZTLCLoFZEbsXDDy9DvDMpEF jmLCg1lFgTx1Gmj/sWPMja29gvybLYdBSO0lV73aUP2S3rwRgmCpEvh8/sd5TFu1OtewsX4b 1dt9L7ku2sVsx1sh18moi+iUkz6BElno+oBgPGc8NrrDOYHK+Aw2Ko/SZhG0eFa6w/YxuJg3 INMFakvaiiftS6o/qMTTB9KZ2vei2HQ/ua/FoqD+adCYIiMCgGHtdyDOrHQLxZhupvSuAr9V vO30ZpUfx98rjGFRty7QtxCTVDRa2DuYD6vgUNb0kCwrWeQIgwXGEVCEyxYJutOEM5d7leUo MX8zMoT2o3L2E0HdfArj7OmwiYAOaEcWy/LFvOvaJ/mfF5auqqUuLByDwD2RgqMhPwalPV8D prTHfiKm5ITFUD8AYFQvGs6F9kb45ZwnLCGAI9R4eiNSQvQSdwZ6ZvZuAdTzaUa3XcDZogMb a6dhPiFfhSaHLfbtgCgFvlKkN2s0RyqZhJPR4f3UYFEj2pmE2QARAQABzSxIYW5zLVdlcm5l ciBSb2l0enNjaCA8aHdyb2l0enNjaEBwb3N0ZW8ubmV0PsLBfQQTAQgAJwUCXdE9RgIbIwUJ CWYBgAULCQgHAg In-Reply-To: Content-Language: en-US Received-SPF: pass client-ip=185.67.36.66; envelope-from=zelphirkaltstahl@posteo.de; helo=mout02.posteo.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/12 16:33:24 X-ACL-Warn: Detected OS = Linux 3.11 and newer 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:16676 Archived-At: Hi! On 7/12/20 6:08 PM, Catonano wrote: > Il giorno sab 11 lug 2020 alle ore 12:14 Chris Vine > ha scritto: > >> On Sat, 11 Jul 2020 02:19:43 +0200 >> Zelphir Kaltstahl wrote: >> [snip] >>> I would be glad, if any non-optimal example was extended or updated b= y a >>> more knowledgeable person or I was told what I could improve in some >>> example. The examples in the repository are only, what I was able to >>> understand and I often find myself looking up, how to do something ag= ain. >>> >>> If anyone wants to take any example and put it in the docs, go ahead.= >>> Only don't think that my examples are the last word on how to do thin= gs. >>> Far from it! >>> >>> About the exceptions thing: Aha! I should look into that again. I >>> thought the "conditions" thing was already pretty cool and useful. On= ce >>> an exception happens, you can react on it. I did not understand the >>> "call/ec helper" part, but perhaps I can understand it, when I check = the >>> docs for the new exceptions in Guile 3. >> The issue is that "non-continuable" in "non-continuable exception" doe= s >> not mean an exception that the program cannot survive, it means an >> exception for which, after handling, control cannot return to the poin= t >> at which the exception was raised[1]. (To answer the question in your= >> following email, continuable exceptions are in some sense analogous to= >> common lisp restarts.) Most guile exceptions are non-continuable. Th= e >> point arising from this is that in the case of a non-continuable >> exception the handler procedure passed to with-exception-handler must >> not return, or a &non-continuable exception will be raised when >> control does attempt to return. >> >> With R6RS/R7RS's with-exception-handler, for non-continuable exception= s >> the handler procedure should normally therefore either invoke a call/e= c >> continuation object to unwind the stack to the point where the >> exception is handled, or it should (after it has done what it is >> intended to do) re-raise the exception to be handled and/or unwound >> elsewhere. Guile-3.0's with-exception-handler procedure will do the >> former for you automatically if you set its #:unwind? argument to >> true. The nearest to guile-2.2's catch expression in guile-3.0's >> exception system is to use with-exception-handler with #:unwind? set >> as #t. R6RS/R7RS's guard form is a wrapper for this which also >> incorporates a cond form to enable different exception types to be >> handled by different handlers. >> >> I therefore suggest that your first example using >> with-exception-handler should set #:unwind? to #t so that the program >> does not end with a &non-continuable exception. I also suggest that, >> if intended for guile-3.0 and not guile-2.2, you should use guile's >> exception objects rather than R6RS conditions (basically you use >> 'make-exception' instead of 'condition' - the two are in effect the >> same). >> > > If it can be of any help, I applied your suggestions to the original > example > > This is supposed to be compatible with Guile 3.x only > > Here it is (a question follows) > > (define even-simpler-display > (lambda (sth) > (display > (simple-format > #f "~a\n" sth)))) > > > (define divide > (lambda (a b) > (cond > [(=3D b 0) > (raise-continuable > (make-exception > (make-exception-with-message "division by zero") > (make-exception-with-irritants (list a b)) > (make-exception-with-origin 'divide)))] > [else > (/ a b)]))) > > > (with-exception-handler > (lambda (conditions-or-value) > (even-simpler-display > ;; We can get the simple exceptions from a compound exception wi= th > the > ;; `simple-exceptions` getter. > (simple-exceptions conditions-or-value))) > (lambda () > (divide 2 0)) > #:unwind? #t) > > I run this in the REPL and it seems to work > > The question, now, is: > > say that the exception handler knows (somehow) that the correct divisor= is > 1 rather than 0 > > So we are saying that this exception is continuable > > How would we continue ? > > Can "divide" return as if it had been called with 1 as its second argum= ent ? > > Or have I misunderstood ? > > How would you go about that ? Ah, I started putting "to do changes" in a list to apply them later, with better understanding: https://notabug.org/ZelphirKaltstahl/guile-examples/src/d670fa02369918cd3= fa896cc19d5aa82966f64a3/exception-handling/notes.org I was going to come back to points, if I do not understand anything properly. Perhaps I can already copy some parts from here^^ Thanks! Zelphir