unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Attila Lendvai <attila@lendvai.name>
To: Maxime Devos <maximedevos@telenet.be>
Cc: "46009@debbugs.gnu.org" <46009@debbugs.gnu.org>,
	Christopher Baines <mail@cbaines.net>,
	"guile-devel@gnu.org" <guile-devel@gnu.org>
Subject: bug#46009: exception from inside false-if-exception?
Date: Mon, 17 Jun 2024 21:45:42 +0000	[thread overview]
Message-ID: <ZoTxVfkW_yf_11HX8eZqRH2bS1CpxEVIk6Rf8DFiu-Z1TbzqPCrjk7lEXgi9GQTNwt3Ku6nIjzgFFkP54P-vk-fvaRGpxvU43hgikCy6Kfc=__43525.1128555805$1718660804$gmane$org@lendvai.name> (raw)
In-Reply-To: <20240617225055.ckqu2C0045M5ED401kquFP@laurent.telenet-ops.be>

[-- Attachment #1: Type: text/plain, Size: 3514 bytes --]

> What is lousy and expectation-violating about a keyword argument
> doing what it name describes?


well, this should have been discussed at the R6RS committee, but...

an API is facilitating efficient reading comprehension when the "verbs" are closer to the beginning of the "sentence" (the sexp), and nothing later in the sentence adjusts the meaning of the verb fundamentally. and especially not a keyword arg at the end of the sentence that is not even mandatory, and defaults to one of the rather different possibilities.

in this case, it's a primitive to catch and handle exceptions. and it's possible to implement both #:unwind? #t and #f so that when the handler returns then the control flow continues at the guard, and never at the RAISE. it's just that one version would call the handler before unwinding.


> If you have unwinded, it’s too late to return return from the raise
> (unless the implementation is doing delimited continuations
> shenanigans, which maybe you had in mind?), which explains the
> behaviour for #:unwind #true.


i didn't have anything on my mind, and that's the point. i'm simply new to scheme. now that i've learned it, i'll learn to live with it.

put another way, my learning curve would have been much steeper if the two, rather different behaviors were defined under two distinct names (or at least mentioned with bold in the documentation).


> That said, I would prefer it to be named something like [#:handler-context 'raise]/[#:handler-context 'guard]


that would be better, but i still wouldn't like the fact that it's focusing on the dynamic context of the handler, instead of the different flow of control.

for reference, in CL they are called HANDLER-CASE and HANDLER-BIND, with completely different syntaxes.



> Wait where did this happen? You say what’s happening, but you don’t
> seem to be referring to false-if-exception stuff, and you didn’t
> mention continuation barriers earlier.


this has caused me layers of confusion, which is sadly reflected in my mails.

guile prints a backtrace without any prelude, which made me think that it's my own code that is printing this backtrace and exception in the logs (remember, i'm working on nested error handling and logging in shepherd). then 3.0.9 does something funny with the control flow, which further made me believe that i'm logging an exception coming from inside FALSE-IF-EXCEPTION and it's somehow flying past my error handler, and reaching fibers.

and i think i'm still confused about a possible continuation barrier being injected somewhere that probably/maybe causes the exception from inside FALSE-IF-EXCEPTION somehow ending up at fibers instead of my error handler. but at this point i'm reaching the frontier of my understanding of scheme, delimited continuations, fibers, etc.

so, one step at a time. once this test.scm is clear, and i'm able to run shepherd on guile-next, then i'll get back to investigate my original issue in its original context.


> It would be helpful to include in test.scm what the expected output
> would be and what unexpected output is encountered.


i've attached a new test.scm that contains the output of two runs, one with 3.0.9, and one with guile HEAD (more specifically, guile-next in guix, which is almost guile HEAD).

HTH,

--
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“Life becomes easier when you learn to accept the apology you never got.”
	— Robert Brault

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: test.scm --]
[-- Type: text/x-scheme; name=test.scm, Size: 3921 bytes --]

#!/usr/bin/env -S guile --no-auto-compile -e main -s
!#

(use-modules (ice-9 control))

(define* (test #:key (unwind? #f))
  (let/ec return
    (with-exception-handler
        (let ((nested #f))
          (lambda (c-level-1)
            (if nested
                (begin
                  (format #t "level 1 handler got called recursively~%")
                  'level-1-handler-nested)
                (begin
                  (set! nested #t)
                  (with-exception-handler
                      (lambda (c-level-2)
                        (begin
                          (format #t "level 2 handler got error ~A~%" c-level-2)
                          (format #t "level 2 handler is returning~%")
                          (return 'level-2-handler)))
                    (lambda ()
                      (format #t "level 1 handler~%")
                      (error "let's signal a nested error...")
                      (format #t "level 1 handler is returning~%")
                      (return 'level-1-handler))
                    #:unwind? unwind?)))))
      (lambda ()
        (error "let's signal an error...")
        'thunk)
      #:unwind? unwind?)))

(define (main cmd)
  (unsetenv "COLUMNS")
  (format #t "~%~%*** calling with unwind~%")
  (format #t "return value is: ~A~%" (test #:unwind? #t))
  (format #t "~%~%*** calling without unwind~%")
  (format #t "return value is: ~A~%" (test #:unwind? #f)))

#|
$ guile --version
guile (GNU Guile) 3.0.9
$ guile --no-auto-compile -e main -s ~/workspace/guile/test.scm


*** calling with unwind
level 1 handler
level 2 handler got error #<&compound-exception components: (#<&error> #<&origin origin: #f> #<&message message: "~A"> #<&irritants irritants: ("let's signal a nested error...")> #<&exception-with-kind-and-args kind: misc-error args: (#f "~A" ("let's signal a nested error...") #f)>)>
level 2 handler is returning
return value is: level-2-handler


*** calling without unwind
level 1 handler
Backtrace:
In ice-9/boot-9.scm:
  1752:10 12 (with-exception-handler _ _ #:unwind? _ # _)
In unknown file:
          11 (apply-smob/0 #<thunk 7f8d73313300>)
In ice-9/boot-9.scm:
    724:2 10 (call-with-prompt ("prompt") #<procedure 7f8d73324f80 …> …)
In ice-9/eval.scm:
    619:8  9 (_ #(#(#<directory (guile-user) 7f8d73316c80>)))
    163:9  8 (_ #(#(#<directory (guile-user) 7f8d73316c80>) ("/ho…")))
In ice-9/boot-9.scm:
    724:2  7 (call-with-prompt (let/ec) #<procedure 7f8d73352900 at…> …)
  1752:10  6 (with-exception-handler _ _ #:unwind? _ # _)
In ice-9/eval.scm:
    619:8  5 (_ #(#(#<directory (guile-user) 7f8d73316c80>)))
In ice-9/boot-9.scm:
   2007:7  4 (error _ . _)
  1685:16  3 (raise-exception _ #:continuable? _)
  1752:10  2 (with-exception-handler _ _ #:unwind? _ # _)
In ice-9/eval.scm:
    619:8  1 (_ #(#(#<directory (guile-user) 7f8d73316c80> #<proc…>)))
In ice-9/boot-9.scm:
   2007:7  0 (error _ . _)

ice-9/boot-9.scm:2007:7: In procedure error:
let's signal a nested error...
$
|#




#|
$ /gnu/store/xm08cp3fz3jxq3zddg9cvj59idy3ri8b-guile-3.0.99-git/bin/guile --no-auto-compile -e main -s ~/workspace/guile/test.scm


*** calling with unwind
level 1 handler
level 2 handler got error #<&compound-exception components: (#<&error> #<&origin origin: #f> #<&message message: "~A"> #<&irritants irritants: ("let's signal a nested error...")> #<&exception-with-kind-and-args kind: misc-error args: (#f "~A" ("let's signal a nested error...") #f)>)>
level 2 handler is returning
return value is: level-2-handler


*** calling without unwind
level 1 handler
level 2 handler got error #<&compound-exception components: (#<&error> #<&origin origin: #f> #<&message message: "~A"> #<&irritants irritants: ("let's signal a nested error...")> #<&exception-with-kind-and-args kind: misc-error args: (#f "~A" ("let's signal a nested error...") #f)>)>
level 2 handler is returning
return value is: level-2-handler
$
|#

  parent reply	other threads:[~2024-06-17 21:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <EFwqPXniEWt-XKJDljH6WU5gdrd9NZ7ljHXRhU7vZJBPk9kPpy7K7OEDLX0SjGkZMM38ugEZMuyfMvsD7I5fCIqvwgRaBPZyV8tOpobPyUU=@lendvai.name>
2024-04-29 14:13 ` bug#46009: exception from inside false-if-exception? Maxime Devos
     [not found] ` <87le4wz1s9.fsf@cbaines.net>
     [not found]   ` <KK9h-weV6TT-z77G7nv8HpFWSdI52KcMByBuvPWFDgI2m6yVcjt_xvzPVrYiUrfgBbiycH3UYqw-kXDgd6R5fhMNTkMBK-1rPkzDkK6oMl4=@lendvai.name>
     [not found]     ` <20240506205840.Kuyd2C00E17cfcj01uygoD@xavier.telenet-ops.be>
2024-06-12 16:32       ` Attila Lendvai
     [not found]       ` <RpVsWsoGpFfNnEgFkKVrSOPG__6WbxYVUBWsiPaRB1qR9X3yTenQxN97VRRpCVokam6oNj9BEMSbSgcR2IFGm5UHC15rbaQk6KgrOPrW2Dc=@lendvai.name>
2024-06-17 19:57         ` Attila Lendvai
     [not found]         ` <cKnzun5yW-Q_THEaSos_kxjOFWnNhitKD9PhgZpRW6mbC8NQmCFVnEtUsi8KtkaBBGoqpqpOIBT7U2FRRmk4CsZ2nFuaRdxxNcvHg9ErUt4=@lendvai.name>
2024-06-17 20:50           ` Maxime Devos via Bug reports for GUILE, GNU's Ubiquitous Extension Language
     [not found]           ` <20240617225055.ckqu2C0045M5ED401kquFP@laurent.telenet-ops.be>
2024-06-17 21:45             ` Attila Lendvai [this message]
     [not found]             ` <ZoTxVfkW_yf_11HX8eZqRH2bS1CpxEVIk6Rf8DFiu-Z1TbzqPCrjk7lEXgi9GQTNwt3Ku6nIjzgFFkP54P-vk-fvaRGpxvU43hgikCy6Kfc=@lendvai.name>
2024-06-19 16:51               ` Maxime Devos via Bug reports for GUILE, GNU's Ubiquitous Extension Language
     [not found]               ` <20240619185059.dUqy2C00M0K6dk406UqzfD@michel.telenet-ops.be>
2024-06-19 18:58                 ` Attila Lendvai
     [not found]                 ` <ud0zXDf9dLoy7OTaH1cMKMrfjDXwTDp4yOO8d1IAEeh8LM8tgDZA2D49AFhWtcIAOPlX9pEWcjbrA-Q1YQ-EqRZBtxO6xC2Gu1KQRB1YDC8=@lendvai.name>
2024-06-19 22:03                   ` Maxime Devos via Bug reports for GUILE, GNU's Ubiquitous Extension Language

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='ZoTxVfkW_yf_11HX8eZqRH2bS1CpxEVIk6Rf8DFiu-Z1TbzqPCrjk7lEXgi9GQTNwt3Ku6nIjzgFFkP54P-vk-fvaRGpxvU43hgikCy6Kfc=__43525.1128555805$1718660804$gmane$org@lendvai.name' \
    --to=attila@lendvai.name \
    --cc=46009@debbugs.gnu.org \
    --cc=guile-devel@gnu.org \
    --cc=mail@cbaines.net \
    --cc=maximedevos@telenet.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).