1 (use-modules (srfi srfi-9)
6 ;; @@: Using immutable agendas here, so wouldn't it make sense to
9 (define-immutable-record-type <agenda>
10 (make-agenda-intern queue)
14 (define* (make-agenda #:key (queue (make-q)))
15 (make-agenda-intern queue))
17 (define %current-agenda (make-parameter #f))
19 (define* (start-agenda agenda #:optional stop-condition)
20 (let loop ((agenda agenda))
22 (parameterize ((%current-agenda agenda))
23 (agenda-run-once agenda))))
24 (if (and stop-condition (stop-condition agenda))
28 (define (agenda-run-once agenda)
29 "Run once through the agenda, and produce a new agenda
31 (let ((queue (agenda-queue agenda))
32 (next-queue (make-q)))
33 (while (not (q-empty? queue))
34 (let* ((proc (q-pop! queue))
38 (enq! next-queue new-proc))))
39 ;; @@: We might support delay-wrapped procedures here
41 ((? procedure? new-proc)
43 (((? procedure? new-procs) ...)
48 ;; TODO: Selecting on ports would happen here?
49 ;; Return new agenda, with next queue set
50 (set-field agenda (agenda-queue) next-queue)))