co-routines in a generator added by anandamide on Tue Apr 19 10:22:07 2016


(let* ((G (lambda (things refs) ;this is the generator, well it should be ;)
	   (call/cc (lambda (yield)
		      (let ((a (lambda (cc) ;co-routine 1
				 (let loop ()
				   (if (not (eq? refs '()))
				       (let ((r (list-ref things (car refs))))
					 (set! refs (cdr refs))
					 (yield r)
					 (set! cc (call/cc cc))
					 (loop))))))
			    (b (lambda (cc) ;co-routine 2
				 (let loop ()
				   (if (not (eq? refs '()))
				       (let ((r (list-ref things (car refs))))
					 (set! refs (cdr refs))
					 (yield r)
					 (set! cc (call/cc cc))
					 (loop)))))))
			(lambda ()
			  (a b)))))))
       (F (G '(#\a #\b #\c #\d
	       #\e #\f #\g #\h
	       #\i #\j #\k #\l
	       #\m #\n #\o #\p
	      #\q #\r #\s #\t
	      #\u #\v #\w #\x
	      #\y #\z)
	     '(8 5 12 12 15 23 15 12 4))))
  (display (F)))