3.3. Pruning Combinator

F <x< G

The execution of F <x< G starts by executing F and G in parallel. Whenever F publishes a value, that value is published by the entire execution. When G publishes its first value, that value is bound to x in F, and then the execution of G is immediately killed. A killed expression cannot call any sites or publish any values. During the execution of F, any part of the execution that depends on x will be blocked until x is bound (to the first value published by G). If G never publishes a value, those parts remain blocked forever.

F <P< G

The pruning combinator may include a full pattern P instead of just a variable name. Any value published by G is matched against the pattern P. If this match is successful, then G is killed and all of the bindings of pattern P are made in F. Otherwise, the published value is simply ignored and G continues to execute.

F << G

This is equivalent to using a wildcard pattern, F <_< G. G continues to execute until it publishes a value. Any value published by G will match the pattern. After the successful match, G is killed, but no bindings are made in F. No part of execution of F is suspended by the pruning combinator since there is no variable to be bound.

3.3.1. Syntax

[13]Prune::= Expression <Pattern?< Expression  

Combinator Precedence Level: sequential > parallel > pruning > otherwise [Full Table]

3.3.2. Notable Identities

F <P< G <P< H = (F <P< G) <P< H (Left Associative)

3.3.3. Type

The type of F <P< G is the type of F in the context ΓG, where ΓG is the result of matching the pattern P against the type of G.

3.3.4. Examples

Exclusive Publication
{- Simulate a coin toss by publishing either "heads" or "tails" arbitrarily -}

x <x< ("heads" | "tails")

{-
OUTPUT:
"heads"
-}
{-
OUTPUT:
"tails"
-}
Print First Result
include "search.inc"

{- Query Google and Yahoo for a search result
   Print out the result that arrives first; ignore the other result
-}

Println(result) <result< ( Google("cupcake") | Yahoo("cupcake") )
Pattern Publication
{- Publish either 9 or 25, but not 16. -}

x*x <(x,true)< ( (3,true) | (4,false) | (5,true) )

{-
OUTPUT:
9
-}
{-
OUTPUT:
25
-}
Timed Termination
{- Print all publications of the metronome function for 90 msec 
   (after the execution of metronome starts). 
   Then kill metronome.  Note that metronome(20) publishes a
   signal every 20 msec.
-}

stop << (metronome(20) >x> Println(x) >> stop | Rwait(90) )

{-
OUTPUT:
signal
signal
signal
signal
signal
-}

3.3.5. Related Links

Related Tutorial Sections