(define x 5) (define (square x) (* x x)) ; try ; (square 12) ; (define sq (lambda (x) (* x x))) (define (factorial n) (if (= n 0) 1 (* n (factorial (- n 1))))) ; try ; (factorial 100) (define (hen_na_square x) (set! x (* x x)) x) (define (bar x) (call-with-current-continuation (lambda (k) (+ 100 (if (= x 0) 1 (k x)))))) ; try ; (bar 0) ; (bar 1) (define (multlist0 xs) (if (null? xs) 1 (begin (display (car xs)) ; (display " ") ; (* (car xs) (multlist0 (cdr xs)))))) (define (multlist xs) (call-with-current-continuation (lambda (k) (define (aux xs) (if (null? xs) 1 (if (= 0 (car xs)) (k 0) (begin (display (car xs)) ; (display " ") ; (* (car xs) (aux (cdr xs))))))) (aux xs)))) ; try ; (multlist '(1 2 3 4 5 6)) ; (multlist '(1 2 3 0 5 6)) ; (multlist '(0 2 3 4 5 6)) (define (increase n k) (if (> n 10) '() (begin (display " i:") (display n) (increase (+ n 1) (call-with-current-continuation k))))) (define (decrease n k) (if (< n 0) '() (begin (display " d:") (display n) (decrease (- n 1) (call-with-current-continuation k))))) ; try ; (increase 0 (lambda (k) (decrease 10 k))) ; (define (yinyang) ; (let* ((yin ; ((lambda (cc) (display #\@) cc) (call-with-current-continuation (lambda (c) c)))) ; (yang ; ((lambda (cc) (display #\*) cc) (call-with-current-continuation (lambda (c) c)))) ) ; (yin yang))) ; don't try -- infinite loop ; (yinyang)