unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Jérémy Korwin-Zmijowski" <jeremy@korwin-zmijowski.fr>
To: guile-user <guile-user@gnu.org>
Subject: with-exception-handler experiment
Date: Tue, 8 Mar 2022 23:10:26 +0100	[thread overview]
Message-ID: <de6f14b7-9d32-57c6-4345-3f6f3ad7aac7@korwin-zmijowski.fr> (raw)


[-- Attachment #1.1.1: Type: text/plain, Size: 1648 bytes --]

Hello Guilers,

Hope you are all fine and safe.

In the following code, I have a test which should check if my result is 
correct.

If you change the expected string value "1 run, 1 failed" the assert 
procedure does not throw.

What happen ? The doc about *with-exception-handler* say things about 
unwinding, dynamic environment, continuation of the error… Which I 
barely understand. And here I guess I miss something.

    ;;;; code under test
    (define runner
       (let ([result '(0 0)])
         (case-lambda
           [() (lambda (proc) (run-and-count proc result) result)]
           [(setup) (lambda (proc) (setup) (run-and-count proc result))]
           [(setup teardown) (lambda (proc) (setup) (run-and-count proc
    result) (teardown))])))
    (define (run-and-count proc result)
       (with-exception-handler
           (lambda (e)
         (list (1+ (car result)) (1+ (cadr result))))
         (lambda ()
           (proc)
           (list (1+ (car result)) (cadr result)))
         #:unwind? #t))
    (define (summary result) (format #f "~A run, ~A failed" (car result)
    (cadr result)))
    ;;;; tests
    (import (rnrs))
    (define (test-failed-result)
       (let ([test-proc (lambda () (raise-exception (make-exception)))])
         (define test-run (runner))
         (define result (test-run test-proc))
         (assert (string=? "1 run, 1 failed" (summary result)))))
    (define run (runner))
    (run test-failed-result)

-- 
Jérémy Korwin-Zmijowski

GPG: 036B 4D54 B7B4 D6C8 DA62 2746 700F 5E0C CBB2 E2D1


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 2525 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 665 bytes --]

             reply	other threads:[~2022-03-08 22:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08 22:10 Jérémy Korwin-Zmijowski [this message]
2022-03-09 14:34 ` with-exception-handler experiment Olivier Dion via General Guile related discussions
2022-03-09 16:54   ` Jérémy Korwin-Zmijowski

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=de6f14b7-9d32-57c6-4345-3f6f3ad7aac7@korwin-zmijowski.fr \
    --to=jeremy@korwin-zmijowski.fr \
    --cc=guile-user@gnu.org \
    /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).