High Level Syntax for Syndicate
1 Instantaneous Actions (I)
spawn
dataspace
send!
assert!
retract!
2 Ongoing Behaviors (O)
state
until
forever
during
assert
on
3 Events (E)
message
asserted
retracted
rising-edge
4 Patterns
6.12

High Level Syntax for Syndicate

 (require syndicate/actor) package: syndicate

1 Instantaneous Actions (I)

syntax

(spawn I ...)

Spawns an actor that executes each instantaneous action I in sequence.

syntax

(dataspace I ...)

Spawns a dataspace as a child of the dataspace enclosing the executing actor. The new dataspace executes each instantaneous action I.

procedure

(send! v [#:meta-level level])  void?

  v : any/c
  level : natural-number/c = 0
Sends a message with body v. The message is sent level dataspaces removed from the dataspace containing the actor performing the send!.

procedure

(assert! v [#:meta-level level])  void?

  v : any/c
  level : natural-number/c = 0
Asserts the value of v until either explicitly retracted via retract! or the immediately enclosing actor exits. level specifies which dataspace the assertion should be made, in terms of relative distance from the dataspace containing the enclosing actor.

procedure

(retract! v [#:meta-level level])  void?

  v : any/c
  level : natural-number/c = 0
Retracts any assertions made by the immediately enclosing actor at level dataspaces above the enclosing dataspace of the form v.

2 Ongoing Behaviors (O)

syntax

(state maybe-init (maybe-bindings O ...) ([E I ...] ...))

 
maybe-init = 
  | #:init [I ...]
     
maybe-bindings = 
  | #:collect ([id init] ...)
 
  id : identifier?
Spawns a new actor with ongoing behaviors O ... that runs until a termination event is detected.

The optional #:init [I ...] provides a sequence of initialization actions. The initial actions are executed before the ongoing behaviors begin but after the interests of the state actor are established.

The optional #:collect [(id init) ...] clause introduces bindings that are visible within the body of the state actor. Each binding id is initialized to the corresponding init expression. The bindings are updated when an ongoing behavior executes an instantaneous event, such as the result of an on behavior. The new bindings are in the form of a values form, with the new values in the same order and number as in the #:collect.

The ongoing behaviors O ... are run simultaneously until the state actor exits.

Each [E I ...] specifies a termination event E of the actor. When a termination event E activates, the corresponding Is are executed. The state actor then exits, with the same result of the final I action.

syntax

(until E
       maybe-init
       maybe-bindings
       maybe-done
       O ...)
 
maybe-init = 
  | #:init [I ...]
     
maybe-bindings = 
  | #:collect ([id init] ...)
     
maybe-done = 
  | #:done [I ...]
 
  id : identifier?
An until behavior corresponds to a state behavior with only one termination event, given by E. The final result of the until behavior is the values of the #:collect bindings in scope from any parent actors followed by the final values of the until actor’s bindings. The actions in a #:done clause are executed after the termination event but before the until actor exits.

syntax

(forever maybe-init
  maybe-bindings
  O ...)
 
maybe-init = 
  | #:init [I ...]
     
maybe-bindings = 
  | #:collect ([id init] ...)
 
  id : identifier?
The forever behavior is analogous to a state form with no termination events.

syntax

(during pat O ...)

Runs the behaviors O ... for the duration of each assertion matching pat.

Roughly equivalent to (on (asserted pat) (until (retracted pat) O ...)) where the pat in the until clause is specialized to the actual value matched by pat in the asserted clause.

syntax

(assert maybe-pred exp maybe-level)

 
maybe-pred = 
  | #:when pred
     
maybe-level = 
  | #:meta-level level
 
  pred : boolean?
  level : natural-number/c
Makes the assertion exp while the enclosing actor is running. If a #:when predicate is given, the assertion is made conditionally on the predicate expression evaluating to true.

syntax

(on E
    I ...)
When the event E becomes active, executes the instantaneous actions I ... in the body. The result of the final action is the result of the entire behavior.

3 Events (E)

syntax

(message pat)

Activates when a message is received with a body matching pat. The message event establishes the enclosing actor’s interest in pat.

syntax

(asserted pat)

Activates when a patch is received with an added assertion matching pat. Establishes the enclosing actor’s interest in pat.

syntax

(retracted pat)

Similar to asserted, except for assertions removed in a patch.

syntax

(rising-edge expr)

Activates when expr evaluates to anything besides #f (having previously evaluated to #f). The condition is checked after each received event, corresponding to after each instantaneous action is executed.

4 Patterns

  pat = 
  | _
  | $id
  | ($ id pat)
  | (? pred pat)
  | (ctor pat ...)
  | expr

_ matches anything.

$id matches anything and binds the value to id.

($ id pat) matches values that match pat and binds the value to id.

(? pred pat) matches values where (pred val) is not #f and that match pat.

(ctor pat ...) matches values built by applying the constructor ctor to values matching pat ....

expr patterns match values that are exactly equal to expr.