Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Occam (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Overview== In the following examples indentation and formatting are critical for parsing the code: expressions are terminated by the end of the line, lists of expressions need to be on the same level of indentation. This feature, named the [[off-side rule]], is also found in other languages such as [[Haskell]] and [[Python (programming language)|Python]]. Communication between processes work through named ''[[Channel (programming)|channels]]''. One process outputs data to a channel via <code>!</code> while another one inputs data with <code>?</code>. Input and output cannot proceed until the other end is ready to accept or offer data. (In the ''not proceeding'' case it is often said that the process ''[[Blocking (computing)|blocks]]'' on the channel. However, the program will neither spin nor poll; thus terms like ''wait'', ''hang'' or ''yield'' may also convey the behaviour; also in the context that it will not ''block'' other independent processes from running.) Examples (c is a variable): keyboard ? c screen ! c <code>SEQ</code> introduces a list of expressions that are evaluated sequentially. This is not implicit as it is in most other programming languages. Example: SEQ x := x + 1 y := x * x <code>PAR</code> begins a list of expressions that may be evaluated concurrently. Example: PAR p() q() <code>ALT</code> specifies a list of ''[[Guard (computer science)|guarded]]'' commands. The guards are a combination of a Boolean condition and an input expression, both optional. Each guard for which the condition is true and the input channel is ready is successful. One of the successful alternatives is selected for execution. Example: ALT count1 < 100 & c1 ? data SEQ count1 := count1 + 1 merged ! data count2 < 100 & c2 ? data SEQ count2 := count2 + 1 merged ! data status ? request SEQ out ! count1 out ! count2 This will read data from channels c1 or c2 (whichever is ready) and pass it into a merged channel. If countN reaches 100, reads from the corresponding channel will be disabled. A request on the status channel is answered by outputting the counts to <code>out</code>.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)