(define-macro (condition-case var bodyform . handlers) `(catch #t (lambda () ,bodyform) (lambda ,var (case (car ,var) ,@(map (lambda (h) ;; Emacs Lisp `case' handles lone symbols, ;; which is pleasant. `(,(let ((name (car h))) (if (or (eq? 'else name) (pair? name)) name (list name))) ,@(cdr h))) handlers) ,@(if (assq 'else handlers) '() `((else ;; This copy is to workaround a (possibly misguided) ;; `nconc2last' used in the Guile 1.4.x implementation. (let ((copy (list-copy ,var))) (apply throw (car copy) (cdr copy)))))))))) ;;; (put 'condition-case 'scheme-indent-function 2) (define (read-string s) (call-with-input-string s read)) (write-line (condition-case c (if (pair? (cdr (command-line))) (apply throw (map read-string (cdr (command-line)))) 'ok) (bad (simple-format #t "BAD: ~S !~%" (cdr c)) 42) ((a b c) (write c) (newline) (cdr c)) (else (let ((key (car c)) (args (cdr c))) (write-line "ELSE!") (write key) (newline) (write args) (newline) 'else))))