my blog lives here now
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
558 B

6 years ago
  1. (import urn/control/prompt ())
  2. (defun run-tasks (&tasks) ; 1
  3. (loop [(queue tasks)] ; 2
  4. [(empty? queue)] ; 2
  5. (call/p 'task (car queue)
  6. (lambda (k)
  7. (when (alive? k)
  8. (push-cdr! queue k)))) ; 2
  9. (recur (cdr queue))))
  10. (defun yield ()
  11. (abort-to-prompt 'task))
  12. (run-tasks
  13. (lambda ()
  14. (map (lambda (x)
  15. (print! $"loop 1: ~{x}")
  16. (yield))
  17. (range :from 1 :to 5)))
  18. (lambda ()
  19. (map (lambda (x)
  20. (print! $"loop 2: ~{x}")
  21. (yield))
  22. (range :from 1 :to 5))))