The class of processes is the main syntactical extension of JoCaml with respect to Objective Caml. Processes have no result. By convention, we say that processes are executed, while expressions are evaluated to some result. Moreover, expressions may fail to produce a result and instead raise an exception. The matching concept for processes is abnormal termination. When a process terminates abnormally, the JoCaml runtime system issues a warning message.
Those are directly inspired from the join-calculus.
The simplest process is 0 (concrete syntax is the digit 0). This process does nothing.
The processes ( process ) and begin process end execute as process does. Both constructs are semantically equivalent, using one construct or the other is a matter of style.
Asynchronous send expr1 expr2 evaluates expr1 to an asynchronous channel and expr2 to a value. Then, the value is sent on the channel. Notice that the syntax is the one of function application, but in process context. Although the syntax is quite general, common usage is simpler. Most often, expr1 is a channel name, while expr2 is a tuple of expressions : lowercase-ident ( expr1, expr2,..., exprk ).
The operator & is the parallel composition. Executing process1 & process2 amounts to executing process1 and process2 concurrently.
The process reply expr to lowercase-ident sends the value of expr as a reply on the synchronous channel lowercase-ident, which must be the name of a synchronous channel. The reply construct is of course to be used while defining the receiving side of a synchronous channel. On the other side, sending a message on a synchronous channel is very similar to calling a function, and the replied expr is like the value returned by a function call.
There are severe linearity constraints over the usage of reply. Linearity constraints here mean that the compiler enforces that exactly one reply to a given channel is allowed. For instance, in process1 & process2, the processes process1 and process2 must reply to disjoint sets of channels; while, in if expr then process1 else process2, the processes process1 and process2 must reply to the same channels.
Composed processes are the equivalent of some of the control structures of Objective Caml, but at the process level.
The process expr ; process evaluates expr first, then it executes process. The expression must be of unit type (by contrast with Objective Caml). Notice that the item before the semicolon ; is an expression, not a process — a process there would be meaningless.
Operator & binds tighter than operator ;. As a result, expr ; process1 & process2 is legal syntax and expr evaluates before both process1 and process2 execute. Moreover, process1 & expr ; process2 is illegal syntax.
Executing the process if expr then process1 else process2 executes process1 if expr evaluates to the boolean true, and process2 if expr1 evaluates to the boolean false.
The else process2 part can be omitted, in which case it defaults to else 0.
Those two constructs are like their (Objective Caml) expression counterpart, except that they are processes and that they introduce bindings of names to values over processes in place of expressions.
The process equivalent of the traditional for loop. Iterations are executed concurrently.
Local definition of channels by a join-definition is possible inside processes.