#!/usr/local/bin/guile \ -e main -s !# ;;; $Id: except.guile,v 1.3 2001/06/29 23:12:37 doug Exp $ ;;; http://www.bagley.org/~doug/shootout/ (use-modules (ice-9 format)) (define HI 0) (define LO 0) (define (some_fun n) (catch #t (lambda () (hi_fun n)) (lambda args #f))) (define (hi_fun n) (catch 'Hi_Exception (lambda () (lo_fun n)) (lambda args (set! HI (+ HI 1))))) (define (lo_fun n) (catch 'Lo_Exception (lambda () (blowup n)) (lambda args (set! LO (+ LO 1))))) (define (blowup n) (if (= 0 (modulo n 2)) (throw 'Hi_Exception) (throw 'Lo_Exception))) (define (main args) (let* ((n (or (and (= (length args) 2) (string->number (cadr args))) 1))) (do ((i 0 (+ i 1))) ((= i n)) (some_fun i))) (display (format "Exceptions: HI=~D / LO=~D\n" HI LO)))