;Zeming Chen ;A19b ;Final Exam Problems #| write a procedure using call-with-values to split a list into two sets where each sets contains either the elements with odd number index or the elements with even number index |# (define split (lambda (ls ) (if (or (null? ls ) (null? (cdr ls ))) (values ls ’()) (call-with-values (lambda () (split (cddr ls ))) (lambda (odd even ) (values (cons (car ls ) odd ) (cons (cadr ls ) even ))))))) ;example ;(split ’(a b c d e f )) -> ;(a c e) ;(b d f ) #| using the given code for a infinite loop and call/cc to write a counter that will print out the counts in every loop |# (define infinite-loop (lambda (procedure) (letrec ((loop (lambda () (procedure) (loop)))) (loop)))) (define count-to-n (lambda (n) (let ((receiver (lambda (exit) (let ((count 0)) (infinite-loop (lambda () (if (= count n) (exit count) (begin (pretty-print "The count is: ") (pretty-print count) (set! count (+ count 1)))))))))) (call/cc receiver)))) #| (count-to-n 10) "The count is: " 0 "The count is: " 1 "The count is: " 2 "The count is: " 3 "The count is: " 4 "The count is: " 5 "The count is: " 6 "The count is: " 7 "The count is: " 8 "The count is: " 9 10 |#