From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Catonano Newsgroups: gmane.lisp.guile.user Subject: Re: "Missing" libraries/concepts found in other languages/ecosystems? Date: Sun, 12 Jul 2020 18:08:33 +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" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37713"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Guile User To: Chris Vine Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Jul 12 18:09:03 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 1jueXH-0009hJ-AW for guile-user@m.gmane-mx.org; Sun, 12 Jul 2020 18:09:03 +0200 Original-Received: from localhost ([::1]:43742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jueXF-0000xV-W7 for guile-user@m.gmane-mx.org; Sun, 12 Jul 2020 12:09:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jueX6-0000xP-EZ for guile-user@gnu.org; Sun, 12 Jul 2020 12:08:52 -0400 Original-Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]:42114) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jueX4-0004oK-Ds for guile-user@gnu.org; Sun, 12 Jul 2020 12:08:52 -0400 Original-Received: by mail-io1-xd30.google.com with SMTP id c16so10933152ioi.9 for ; Sun, 12 Jul 2020 09:08:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9R5TfzQLnpE/wnFFrhScvDjg38vQ82r6A8iDXyzXKuU=; b=i/egDpfxTf1XNQRvMtONb+d+DpRI4NfImB/YpVdOhL9ZEt26ZxUMlpffxIChhtLfGT DS3LZuXHwcZCes5IAQSrOha4bT3/h55Nf67OogDOXzj471OKkMjI2+D93Jp8o2eB55ft 9yRVWPUxWdNiFZwf/0lLiw56XSficNO7Uo/+YYXXidxZaNkRbzYKSglVv/O23/hgF4yq ZTdsymLDbRTYF12S2Plt9fqK6Anu7RggUAlM+TWY8eViUSSXzT3KiYz0XjaCwfp49fUJ 04ddQtK9LVdX28qDXpzQ+bj0gZN8Z0+TutXSyGa2GoQwsWyScqLIuMnZvRTpL+cdxRaO FD1w== 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=9R5TfzQLnpE/wnFFrhScvDjg38vQ82r6A8iDXyzXKuU=; b=IBd+U7webYx7DcrBHNDGH+7RJFfoO2Kl+fYVWkjvZ3ML4boC35BQkYfhh9NhrZ0H3R 7aANxPCvJLbEUSIMNQYNN+KNXfOFF4E5YjnqjZAYYtt3lL78ms3OCJVVAk3zMdvDBkzj 6/rKZgcJJnHlcJgOu/5pLQcypX99gb1d9B+KghT4NgrXJbizDiOhOMJkvQqUewviG3d3 w55IryElGPrJb8mKxJmE4+J4SkneWvW4bF23M1RyCIWzPGic3eWqH7mgD3CvOfMyJNwh kDg+y/RHCmh/E9mrkDFpqIlFzJOMCOvFIohp1dA+uEGwsGrvRylV8X6UoW53kiYfbkoz VI+w== X-Gm-Message-State: AOAM530XmsMgFcUhDqqWjnwu41RlrMvJWbCmcSia5diKYM0mNsHkSE4R eKauAyeZWPbMlUdbvS1Yj/i68A87TRl3ERw9Iw== X-Google-Smtp-Source: ABdhPJzJSMxmz6aFTnzGNrmhPkPQseOl+ZOgoZU4upgSo0QBRpdWed8Gir+4xyVPk6OYcTZGJJ4WgbwCpEWoG2DHi1o= X-Received: by 2002:a6b:c343:: with SMTP id t64mr2505797iof.66.1594570125943; Sun, 12 Jul 2020 09:08:45 -0700 (PDT) In-Reply-To: <20200711111359.acacd7d4a6b328bab44ba11e@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::d30; envelope-from=catonano@gmail.com; helo=mail-io1-xd30.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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.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:16670 Archived-At: 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 by 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 again. > > > > 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 things. > > 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. Once > > 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" does > not mean an exception that the program cannot survive, it means an > exception for which, after handling, control cannot return to the point > 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. The > 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 exceptions > the handler procedure should normally therefore either invoke a call/ec > 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 [(= 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 with 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 argument ? Or have I misunderstood ? How would you go about that ?