5.4 Programs
5.4.1 Validity
5.4.2 Modules
5.4.3 Steps
5.4.4 Local Steps
5.4.5 Consensus Steps
5.4.6 Computations
5.4.3 Steps
On this page:
5.4.3.1 Statements
5.4.3.1.1 only and each
only
each
5.4.3.1.2 publish, pay, and timeout
publish
pay
timeout
5.4.3.1.3 wait
wait
5.4.3.1.4 exit
exit
5.4.3.2 Expressions
5.4.3.2.1 unknowable
unknowable
5.4.3.2.2 close  To
close  To
5.4.3 Steps

A Reach step occurs in the body of Reach.App or in the continuation of a commit statement. It represents the actions taken by each of the participants in an application.

5.4.3.1 Statements

Any statements valid for a computation are valid for a step. However, some additional statements are allowed.

5.4.3.1.1 only and each

Alice.only(() => {
  const pretzel = interact.random(); }); 

A local step statement is written PART.only(() => BLOCK), where PART is a participant identifier and BLOCK is a block. Any bindings defined within the block of a local step are available in the statement’s tail as new local state. For example,

Alice.only(() => {
  const x = 3; });
Alice.only(() => {
  const y = x + 1; }); 

is a valid program where Alice’s local state includes the private values x (bound to 3) and y (bound to 4). However, such bindings are not consensus state, so they are purely local state. For example,

Alice.only(() => {
  const x = 3; });
Bob.only(() => {
  const y = x + 1; }); 

is an invalid program, because Bob does not know x.

each([Alice, Bob], () => {
  const pretzel = interact.random(); }); 

An each local step statement can be written as each(PART_TUPLE () => BLOCK), where PART_TUPLE is a tuple of participants and BLOCK is a block. It is an abbreviation of many local step statements that could have been written with only.

5.4.3.1.2 publish, pay, and timeout

Alice.publish(wagerAmount)
     .pay(wagerAmount)
     .timeout(DELAY, () => {
       Bob.publish();
       commit();
       return false; }); 
Alice.publish(wagerAmount)
     .pay(wagerAmount)
     .timeout(DELAY, closeTo(Bob, false)); 

A consensus transfer is written PART.publish(ID_0, ..., ID_n).pay(PAY_EXPR).timeout(DELAY_EXPR, () => TIMEOUT_BLOCK), where PART is a participant identifier, ID_0 through ID_n are identifiers for PART’s public local state, PAY_EXPR is a public expression evaluating to an amount of network tokens, DELAY_EXPR is a public expression that depends on only consensus state and evaluates to a time delta represented by a natural number, TIMEOUT_BLOCK is a timeout block, which will be executed after DELAY_EXPR units of time have passed from the end of the last consensus step without PART executing this consensus transfer. The continuation of a consensus transfer statement is a consensus step, which is finalized with a commit statement. The continuation of a timeout block is the same as the continuation as the continuation as the function the timeout occurs within.

See the guide section on non-participation to undertand when to use timeouts and how to use them most effectively.

The publish component exclusive-or the pay component may be omitted, if either there is no publication or no transfer of network tokens to accompany this consensus transfer. The timeout component may always be omitted. Each component may occur in any order. For example, the following are all valid:

Alice.publish(coinFlip);

Alice.pay(penaltyAmount);

Alice.pay(penaltyAmount).publish(coinFlip);

Alice.publish(coinFlip)
     .timeout(DELAY, () => closeTo(Bob, () => exit()));

Alice.pay(penaltyAmount)
     .timeout(DELAY, () => {
       Bob.publish();
       commit();
       exit(); }); 

If the named participant has not yet joined the application, then this statement has the effect of them joining, after which PART may be used as a address.

5.4.3.1.3 wait

wait(AMT); 

A wait statement, written wait(AMOUNT);, delays the computation until AMOUNT time delta units have passed. It may only occur in a step.

5.4.3.1.4 exit

exit(); 

An exit statement, written exit();, halts the computation. It is a terminator statement, so it must have an empty tail. It may only occur in a step.

5.4.3.2 Expressions

Any expressions valid for a computation are valid for a step. However, some additional expressions are allowed.

5.4.3.2.1 unknowable

unknowable( Notter, Knower(expr_0, ..., expr_N) ) 

A knowledge assertion that the participant Notter does not know the results of the evaluations of expressions expr_0 through expr_N, but that the participant Knower does know those values.

5.4.3.2.2 closeTo

closeTo( Who, after ) 

Returns has participant Who make a publication, then transfer the balance() to Who and end the DApp after executing the function after in a step.