11.2. core: Fundamental sites and operators.

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.

11.2.1. Let

site Let() :: Signal

DefinitePure

When called with no arguments, returns a signal.

11.2.2. Let

site Let(A) :: A

When called with a single argument, returns that argument (behaving as the identity function).

11.2.3. Let

site Let(A, ...) :: (A, ...)

When called with two or more arguments, returns the arguments as a tuple.

11.2.4. Ift

site Ift(Boolean) :: Signal

DefinitePure

Returns a signal if the argument is true, otherwise halts silently.

Example:

-- Publishes: "Always publishes"
  Ift(false) >> "Never publishes"
| Ift(true) >> "Always publishes"

11.2.5. Iff

site Iff(Boolean) :: Signal

DefinitePure

Returns a signal if the argument is false, otherwise halts silently.

Example:

-- Publishes: "Always publishes"
  Iff(false) >> "Always publishes"
| Iff(true) >> "Never publishes"

11.2.6. Error

site Error(String) :: Bot

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)

11.2.7. (+)

site (+)(Number, Number) :: Number

a+b returns the sum of a and b.

11.2.8. (-)

site (-)(Number, Number) :: Number

a-b returns the value of a minus the value of b.

11.2.9. (0-)

site (0-)(Number) :: Number

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

11.2.10. (*)

site (*)(Number, Number) :: Number

a*b returns the product of a and b.

11.2.11. (**)

site (**)(Number, Number) :: Number

a ** b returns ab, i.e. a raised to the bth power.

11.2.12. (/)

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...

11.2.13. (%)

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.

11.2.14. (<:)

site (<:)(Top, Top) :: Boolean

a <: b returns true if a is less than b, and false otherwise.

11.2.15. (<=)

site (<=)(Top, Top) :: Boolean

a <= b returns true if a is less than or equal to b, and false otherwise.

11.2.16. (:>)

site (:>)(Top, Top) :: Boolean

a :> b returns true if a is greater than b, and false otherwise.

11.2.17. (>=)

site (>=)(Top, Top) :: Boolean

a >= b returns true if a is greater than or equal to b, and false otherwise.

11.2.18. (=)

site (=)(Top, Top) :: Boolean

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.

11.2.19. (/=)

site (/=)(Top, Top) :: Boolean

a/=b returns false if a=b, and true otherwise.

11.2.20. (~)

site (~)(Boolean) :: Boolean

Return the logical negation of the argument.

11.2.21. (&&)

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.

11.2.22. (||)

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.

11.2.23. (:)

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)

11.2.24. abs

def abs(Number) :: Number

Publishes the absolute value of the argument.

Implementation. 

              
def abs(Number) :: Number
def abs(x) = if x <: 0 then -x else x


            

11.2.25. signum

def signum(Number) :: Number

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


            

11.2.26. min

def min[A](A,A) :: A

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


            

11.2.27. max

def max[A](A,A) :: A

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



            

11.2.28. Floor

site Floor(Number) :: Integer

Return the greatest integer less than or equal to this number.

11.2.29. Ceil

site Ceil(Number) :: Integer

Return the least integer greater than or equal to this number.

11.2.30. sqrt

def sqrt(Number) :: Integer

Publish the square root of this number. If the number is negative, halt silently.

Implementation. 

              
def sqrt(Number) :: Number
def sqrt(n) = n ** 0.5