; use trampoline technique for continuation passing style
; see here: 
; http://weblambdazero.blogspot.com/2010/07/advanced-recursion-in-newlisp.html

(define (trampoline fun arg)
  (catch
    (while true
      (let ((run (apply fun arg)))
        (setf fun (first run) arg (rest run)))) 
    'result)
  result)

(define (f1 n)
  (println n)
  (if (= n 0)
    (throw "cut")
    (list f2 n)))

(define (f2 n)
  (list f1 (- n 1)))

(trampoline f1 '(10))

;


syntax highlighting with newLISP and syntax.cgi