The simplest expression one can write is a literal value. Executing that expression simply publishes the value.
Orc has four kinds of literal values:
5, -1, 2.71828, ...
"ceci n'est pas une |"
Orc has a standard set of arithmetic, logical, and comparison operators. As in most other programming languages, they are written in the usual infix style. They have Java-like operator precedence, which can be overridden by adding parentheses.
1 + 2publishes
(98 + 2) * 17publishes
4 = 20 / 5publishes
3-5 >= 5-3publishes
true && (false || true)publishes
"leap" + "frog"publishes
3 / 0halts, publishing nothing.
An Orc program interacts with the external world by calling sites. Sites are one of the two fundamental concepts of Orc programming, the other being combinators which we discuss later when covering complex expressions.
A site call in Orc looks like a method, subroutine, or function call in other programming languages.
A site call might publish a useful value, or it might just publish a
it might halt, refusing to publish anything, or it might even wait indefinitely.
Here are some examples:
hello worldto the console and publishes a
Random(10)publishes a random integer from 0 to 9, uniformly distributed.
Browse("http://orc.csres.utexas.edu/")opens a browser window pointing to the Orc home page and publishes a
Error("I AM ERROR")reports an error message on the console, and halts. It publishes nothing.
Rwait(420)waits for 420 milliseconds, then publishes a
Prompt("Username:")requests some input from the user, then publishes the user's response as a string. If the user never responds, the site waits forever.
Even the most basic operations in Orc are sites. For example, all of the operators are actually sites;
2+3 is just another way of writing the site call
By convention, all site names begin with a capital letter.