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

(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))))