#!/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)))