Fundamental sites and operators.
These declarations include both prefix and infix sites (operators). For
consistency, all declarations are written in prefix form, with the site name
followed by the operands. When the site name is surrounded in parentheses, as
in (+)
, it denotes an infix operator.
For a more complete description of the built-in operators and their syntax, see the Operators article.
site Let(A) :: A
When called with a single argument, returns that argument (behaving as the identity function).
site Let(A, ...) :: (A, ...)
When called with two or more arguments, returns the arguments as a tuple.
Definite | Pure |
Returns a signal if the argument is true, otherwise halts silently.
Example:
-- Publishes: "Always publishes" Ift(false) >> "Never publishes" | Ift(true) >> "Always publishes"
Definite | Pure |
Returns a signal if the argument is false, otherwise halts silently.
Example:
-- Publishes: "Always publishes" Iff(false) >> "Always publishes" | Iff(true) >> "Never publishes"
Definite |
Emits the given string as an error message, then halt silently.
Example, using Error
to implement assertions:
def assert(b) = if b then signal else Error("assertion failed") -- Fail with the error message: "assertion failed" assert(false)
Return the additive inverse of the argument.
When this site appears as an operator, it is written in prefix form without the
zero, i.e. -a
site (/)(Number, Number) :: Number
a/b
returns a
divided by b
.
If both arguments have integral types, (/)
performs integral
division, rounding towards zero. Otherwise, it performs floating-point
division. If b=0
, a/b
halts with an error.
Example:
7/3 -- publishes 2 | 7/3.0 -- publishes 2.333...
site (%)(Number, Number) :: Number
a%b
computes the remainder of a/b
. If a
and b
have integral types, then the remainder is given by
the expression a - (a/b)*b
. For a full description, see the
Java Language Specification, 3rd edition.
site (<=)(Top, Top) :: Boolean
a <= b
returns true if a
is less than or equal to b
, and false otherwise.
site (>=)(Top, Top) :: Boolean
a >= b
returns true if a
is greater than or equal to b
, and false otherwise.
a = b
returns true if a
is equal to b
,
and false otherwise. The precise definition of "equal" depends on the values
being compared, but always obeys the rule that if two values are considered
equal, then one may be substituted locally for the other without affecting the
behavior of the program.
Two values with the same object identity are always considered equal. Orc data structures, such as tuples, are equal if their contents are equal. Other types are free to implement their own equality relationship provided it conforms to the rules given here.
Note that although values of different types may be compared with
=
, the substitutability principle requires that such values are
always considered inequal, i.e. the comparison will return false
.
site (&&)(Boolean, Boolean) :: Boolean
Return the logical conjunction of the arguments. This is not a short-circuiting operator; both arguments must publish before the result is computed.
site (||)(Boolean, Boolean) :: Boolean
Return the logical disjunction of the arguments. This is not a short-circuiting operator; both arguments must publish before the result is computed.
site (:)[A](A, List[A]) :: List[A]
The list a:b
is formed by prepending the element a
to
the list b
.
Example:
-- Publishes: (3, [4, 5]) 3:4:5:[] >x:xs> (x,xs)
Publishes the absolute value of the argument.
Implementation.
def abs(Number) :: Number def abs(x) = if x <: 0 then -x else x
signum(a)
publishes -1
if a<0
,
1
if a>0
, and 0
if a=0
.
Implementation.
def signum(Number) :: Number def signum(x) = if x <: 0 then -1 else if x :> 0 then 1 else 0
Publishes the lesser of the arguments. If the arguments are equal, publishes the first argument.
Implementation.
def min[A](A,A) :: A def min(x,y) = if y <: x then y else x
Publishes the greater of the arguments. If the arguments are equal, publishes the second argument.
Implementation.
def max[A](A,A) :: A def max(x,y) = if x :> y then x else y