#!/usr/bin/newlisp

# exception - benchmark
# requires 7.5.1 or later

(context 'MAIN)

(set 'HI 0 'LO 0)

(define (some_function num)
	(catch (hi_function num) 'result)
	(if (not (integer? result))
		(println "we never get here")))

(define (hi_function num)
	(catch (lo_function num) 'result)
	(if (= result 'HI_exception)
		(inc 'HI)
		(throw result)))
		
(define (lo_function num)
	(catch (blowup num) 'result)
	(if (= result 'LO_exception) 
		(inc 'LO)
		(throw result)))

(define (blowup num)
	(if (= (& num 1) 1)
		(throw 'HI_exception)
		(throw 'LO_exception)))

(define (main)
	(dotimes (i n)
		(some_function i))
	(println "Exceptions: HI=" HI " / LO=" LO))
	
(set 'n (integer (nth 2 (main-args))))

(main)

(exit)




syntax highlighting with newLISP and syntax.cgi