Home   1 Introduction > 1.2 Examples > 1.2.7 even
prev next

@x:Act does not support type inheritance. Instead, an alterative mechanism called views are provided. Here is a simple example that produces a view of the int type that restricts the values to only those that are even.


@x:view even {
   @x:func sys:Is(v~int),visible {
      v /+ 2 == 0
   }
}
2~eveneol;
5?eveneol;
10?eveneol

The special "sys:Is" function states what values are "in" the view. The /+ is the remainder operation.

The infix ~ operation asserts that its left operand has the type or view specified by the right operand and returns the value of the left operand. The infix ? operator tests if its left operand has the type or view specified by the right operand.