Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
language:langs:chp [2022/08/02 19:59]
rajit [An example]
language:langs:chp [2023/01/02 07:39]
rajit [Channels in expressions]
Line 158: Line 158:
 If ''A'' is an input port, then ''A'' can participate in a //channel expression//. For example, we can write: If ''A'' is an input port, then ''A'' can participate in a //channel expression//. For example, we can write:
 <code act> <code act>
-*[[A=3 -> X!true;A?+[A=3 -> X!true;A?
- []A!=3 -> X!false;A?+[]A!=3 -> X!false;A?
- ]+]
 </code> </code>
 Here, ''A=3'' is a channel expression. This has the following meaning: first, wait for a value to be pending on the input channel ''A''; then compare it to 3. In other words, this expression includes an //implicit// probe. It also permits the pending value on ''A'' to be inspected. Note that ''A!=3'' //also includes waiting for a value to be pending on the input channel//, and is not the literal negation of the condition corresponding to ''A=3''. In other words, in the program fragment above, the selection statement should be read: wait for a value to be pending on input channel ''A''; if the value is 3, do the first set of statements; otherwise pick the second set of statements. Here, ''A=3'' is a channel expression. This has the following meaning: first, wait for a value to be pending on the input channel ''A''; then compare it to 3. In other words, this expression includes an //implicit// probe. It also permits the pending value on ''A'' to be inspected. Note that ''A!=3'' //also includes waiting for a value to be pending on the input channel//, and is not the literal negation of the condition corresponding to ''A=3''. In other words, in the program fragment above, the selection statement should be read: wait for a value to be pending on input channel ''A''; if the value is 3, do the first set of statements; otherwise pick the second set of statements.
Line 328: Line 328:
 The CHP program: The CHP program:
 <code act> <code act>
-*[ L?x; R!x ]+chp { 
 +   *[ L?x; R!x ] 
 +}
 </code> </code>
 would be written in ''chp-txt'' as would be written in ''chp-txt'' as
 <code act> <code act>
-forever +chp-txt 
-   L?x; R!x+   forever { 
 +      L?x; R!x 
 +   }
 } }
 </code> </code>
Line 339: Line 343:
 The CHP program: The CHP program:
 <code act> <code act>
-*[ L?x; [ x > 0 -> R!x [] else -> skip ] ]+chp { 
 +   *[ L?x; [ x > 0 -> R!x [] else -> skip ] ] 
 +}
 </code> </code>
 would be written would be written
 <code act> <code act>
-forever +chp-txt 
-   recv (L, x); +   forever { 
-   select { +      recv (L, x); 
-     case x > 0 : send (R, x); +      select { 
-     else : skip+        case x > 0 : send (R, x); 
 +        else : skip 
 +      }
    }    }
-}+  
 </code> </code>
- 
-