0
(import urn/control/prompt ())

(defun run-tasks (&tasks) ; 1
  (loop [(queue tasks)] ; 2
    [(empty? queue)]    ; 2
    (call/p 'task (car queue)
      (lambda (k)
        (when (alive? k)
          (push-cdr! queue k)))) ; 2
    (recur (cdr queue))))

(defun yield ()
  (abort-to-prompt 'task))

(run-tasks
  (lambda ()
    (map (lambda (x)
           (print! $"loop 1: ~{x}")
           (yield))
         (range :from 1 :to 5)))
  (lambda ()
    (map (lambda (x)
           (print! $"loop 2: ~{x}")
           (yield))
         (range :from 1 :to 5))))