;;; -*- mode: lisp -*-
;;; $Id: except.cmucl,v 1.2 2001/01/01 17:51:53 doug Exp $
;;; http://www.bagley.org/~doug/shootout/
;;; From: Friedrich Dominicus

(defparameter *hi* 0)
(defparameter *lo* 0)

(defun some-fun (n)
  (catch t
    (hi-fun n)))

(defun hi-fun (n)
  (catch 'Hi_Exception
    (lo-fun n)))
  
(defun lo-fun (n)
  (catch 'Lo_Exception
    (blow-up n))) 
  
(defun blow-up (n)
  (if (evenp n)
      (throw 'Hi_Exception (setf *hi* (1+ *hi*)))
    (throw 'Lo_Exception (setf *lo* (1+ *lo*)))))

  (let ((n (parse-integer (or (car pop11::poparglist) "1"))))
  (setf *hi* 0
    *lo* 0)
  (do ((i 0 (1+ i)))
      ((= i n))
    (some-fun i)))
  (format t "Exceptions: HI=~A / LO=~A~%" *hi* *lo*)