Lecture overview -- Keyboard shortcut: 'u'  Previous page: The catch and throw idea -- Keyboard shortcut: 'p'  Next page: The intuition behind continuations -- Keyboard shortcut: 'n'  Lecture notes - all slides together  Annotated slide -- Keyboard shortcut: 't'  Alphabetic index  Help page about these notes  Course home    Simulation of other Paradigms and Continuations - slide 24 : 43

A catch and throw example
Exit from a list length function in case it discovers a non-empty tail of the list
(define (list-length lst)
  (catch 'exit
    (letrec ((list-length1
               (lambda (lst) 
                 (cond ((null? lst) 0)
                       ((pair? lst) (+ 1 (list-length1 (cdr lst))))
                       (else (throw 'exit 'improper-list))))))
       (list-length1 lst))))
catch and throw are not available in standard Scheme