Control

At least two linguistic mechanisms are necessary to make the computations in programs flexible and powerful: some means of selecting among alternative control flow paths (of statement execution) and some means of causing the repeated execution of statements or sequences of statements. Statements that provide these kinds of capabilities are called control statements. A control structure is a control statement and the collection of statements whose execution it controls. This set of statements is in turn generally structured as a block, which in addition to grouping, also defines a lexical scope.

There are two types of control flow mechanisms:

  • choice - when
  • loop - loop
  • guard - if

Choice type

when(){ case(condition){} case(condition){} _ {} };
when(variable){ is (value){}; is (value){}; _ {}; };
when(variable){ in (iterator){}; in (iterator){}; _ {}; };
when(variable){ has (member){}; has (member){}; _ {}; };
when(variable){ of (type){}; of (type){}; _ {}; };
when(type){ on (channel){}; on (channel){}; };

Condition

when() {
    case (x == 6){ // implementation }
    case (y.set()){ // implementation } 
    _ { // default implementation }
}

Valueation

when(x) {
    is (6){ // implementation }
    is (>7){ // implementation } 
    _ { // default implementation }
}

Iteration

when(2 * x) {
    in ({0..4}){ // implementation }
    in ({ 5, 6, 7, 8, }){ // implementation } 
    _ { // default implementation }
}

Contains

when({4,5,6,7,8,9,0,2,3,1}) {
    has (5){ // implementation }
    has (10){ // implementation } 
    _ { // default implementation }
}

Generics

when(T) {
    of (int){ // implementation }
    of (str){ // implementation } 
    _ { // default implementation }
}

Channel

when(str) {
    on (channel){ // implementation }
    on (channel){ // implementation } 
    _ { // default implementation }
}

Loop type

loop(condition){};
loop(iterable){};

Condition

loop( x == 5 ){
    // implementation
};

Enumeration

loop( x in {..100}){
    // implementation
}

loop( x in {..100}) if ( x % 2 == 0 )){
    // implementation
}

loop( x in {..100} if (( x in somearra ) and ( x in anotherarray ))){
    // implementation
}

Iteration

loop( x in array ){
    // implementation
}

Guard type

The if statement can be used as guard in both when statement and loop statement:


loop( x in {..100} if (( x in somearra ) and ( x in anotherarray ))){
    // implementation
}

when(x) {
    is (6) if (6 of (int)){ // implementation }
    is (7) if (7 in (somearray)){ // implementation } 
    * { // default implementation }http://spack.rtfd.io/
}