; Expoliting reuse of continuations. ; Debugging: ; (define (ex m v) (write (list m v))(newline) v) ; Pattern support: (call/cc (lambda (finish) (let* ((found (let ((tskList '())) (cons (lambda () (if (null? tskList) (finish "done") (let ((nxt (car tskList))) (set! tskList (cdr tskList)) (nxt)))) (lambda (t) (set! tskList (cons t tskList)))))) (yield (car found))(newTsk (cdr found)) (DoS (lambda (n p) (let q ((n n)) (if (zero? n) (yield) (begin (call/cc (lambda (C) (newTsk C) (p n))) (q (- n 1)))))))) ; version of sqrt and point-plot within pattern: (let ( (sqrt (lambda (x) (if (< x 0) (yield) (if (= x 0) 0 (let ((root (sqrt x))) (call/cc (lambda (c) (newTsk (lambda () (c (- root)))) (c root)))))))) (plot (lambda (x y) (write (list "pt=" x y))(newline)(yield)))) ; Application: (let ((gr 5)) (DoS (+ (* 4 gr) 1) (lambda (i) (let ((x (/ (- i (* 2 gr)) gr))) (plot x (sqrt (- 1 (* x x))))))))))))