Previous: , Up: Time   [Contents][Index]


4.3.3 Agendas

(use-modules (sly agenda))

Agendas are used to schedule procedures to be called at distinct points in time. One agenda, stored in the current-agenda parameter, is active at any given time. A global agenda is initially bound and is sufficient for most needs. When a separate scheduler is required (see REPL for one such case), the parameter can be rebound using parameterize or with-agenda form.

Scheme Procedure: make-agenda

Create a new, empty agenda.

Scheme Syntax: agenda? obj

Return #t if obj is an agenda.

Scheme Variable: current-agenda

A parameter containing the current, dynamically scoped agenda object.

Scheme Procedure: agenda-time

Return the time of the current agenda.

Scheme Syntax: with-agenda agenda body

Evaluate body with current-agenda bound to agenda.

Scheme Procedure: agenda-tick!

Increment time by 1 for the current agenda and run scheduled procedures.

Scheme Procedure: agenda-clear!

Remove all scheduled procedures from the current agenda.

Scheme Procedure: schedule thunk [delay]

Schedule thunk to be applied after delay ticks of the current agenda. The default delay is one tick.

Scheme Procedure: schedule-interval thunk interval

Schedule thunk to be applied every interval ticks of the current agenda, forever.

Scheme Procedure: schedule-each thunk

Schedule thunk to be applied upon every tick of the current agenda, forever.

Coroutines become particularly useful for game programming when combined with the agenda. For example, a computer controller opponent could periodically pause its AI algorithm to give the rest of the game world a chance to do some processing. By using the wait procedure, algorithms that span multiple ticks of game time can be written in a straightforward, natural way.

Scheme Procedure: wait delay

Abort the current coroutine prompt and schedule the continuation to be run after delay ticks of the current agenda.


Previous: , Up: Time   [Contents][Index]