[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
I'm missing something obvious about (chicken conditions)
From: |
T . Kurt Bond |
Subject: |
I'm missing something obvious about (chicken conditions) |
Date: |
Tue, 07 Mar 2023 16:40:15 -0500 |
User-agent: |
Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (Gojō) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (x86_64-apple-darwin18.7.0) MULE/6.0 (HANACHIRUSATO) |
I've got two programs, edited down from other slightly larger programs
for clarity. They use condition-case to handle exceptions. I'm
interested in handling a (mine) condition and a (mine too)
differently. One of the program *does* distinguish between the two
exceptions; one of them doesn't. I can't figure out why.
Variant 1 *doesn't* distinguish:
========== my-conditions-var1.scm =============================================
;;;; -*- geiser-scheme-implementation: chicken -*-
(import format)
(import (chicken condition))
(define mine (condition '(mine)))
(define mine-two (condition '(mine) '(two)))
(define (check thunk)
(condition-case (thunk)
[ex (exn i/o)
(format #t "This is an (exn i/o) condition: ~s~%" ex)]
[ex (exn)
(format #t "This is an exn condition of some sort: ~s~%" ex)]
[ex (mine too)
(format #t "This is a (mine too) condition: ~s~%" ex)]
[ex (mine)
(format #t "This is a (mine) condition: ~s~%" ex)]
[ex () (format #t "This is something else: ex: ~s~%" ex)]))
(check (lambda () (/ 1 0)))
(check (lambda () (signal mine)))
(check (lambda () (signal mine-two)))
(check (lambda () (signal (condition '(mine) '(two)))))
(check (lambda () (signal (condition
`(exn msg "bogus message" args "bogus args")
'(i/o)))))
========== End of my-conditions-var1.scm ======================================
Here's the output:
========== my-conditions-var1.out =============================================
This is an exn condition of some sort: #<condition: (exn arithmetic)>
This is a (mine) condition: #<condition: (mine)>
This is a (mine) condition: #<condition: (mine two)>
This is a (mine) condition: #<condition: (mine two)>
This is an (exn i/o) condition: #<condition: (exn i/o)>
========== End of my-conditions-var1.out ======================================
Notice that it's the (mine) branch of the condition-case that catches
both conditions. But it can distinguish between an (exn i/o)
condition and other exn conditions. Why not (mine) and (mine two)?
Here's variant 2, which *does* distinguish:
========== my-conditions-var2.scm =============================================
(import (format))
(import (chicken condition))
(define mine-too (condition '(mine) '(two)))
(define (check a-condition)
(condition-case (signal a-condition)
[ex (mine two) (format #t "This is mine, too: ~s~%" ex)]
[ex (mine) (format #t "This is mine: ~s~%" ex)]
[ex (exn i/o) (format #t "This is an i/o exn: ~s~%" ex)]
[ex (exn) (format #t "This is some kind of exn: ~s~%" ex)]
[ex () (format #t "This is something else: ~s~%" ex)]))
(check (condition '(mine)))
(check (condition '(mine) '(two)))
(check mine-too)
(check (condition '(exn msg "bogus message" args "bogus args") '(i/o)))
(check (condition '(exn msg "bogus message 2" args "bogus args 2")))
(check 'this-is-not-a-condition-but-is-signaled)
========== End of my-conditions-var2.scm ======================================
Here's its output:
========== my-conditions-var2.out =============================================
This is mine: #<condition: (mine)>
This is mine, too: #<condition: (mine two)>
This is mine, too: #<condition: (mine two)>
This is an i/o exn: #<condition: (exn i/o)>
This is some kind of exn: #<condition: (exn)>
This is something else: this-is-not-a-condition-but-is-signaled
========== End of my-conditions-var2.out ======================================
I don't see why the first variant doesn't distinguish between (mine)
and (mine too) and the second variant does. What am I missing?
--
T. Kurt Bond, tkurtbond@gmail.com, tkurtbond.github.io and tkb.tx0.org
- I'm missing something obvious about (chicken conditions),
T . Kurt Bond <=