BRiX
Advanced Computing Environment
Hosted by SourceForge
brix-os project page

Previous: Prototypes ----- Up: Contents ----- Next: Numbers

Common Interfaces

An interface is a group of slot, method and property definitions (no implementations) and is the only way to do multiple inheritance. The interface type is just like any other type and may be be used as the expected type of objects. Because of the multiple inheritance, the position of symbols in the interface vary from one type to another and must always be dynamically queried. However, the symbols can be statically dispatched if the compiler knows the exact subtype at compile-time.

addition_interface: addition of like objects with + operator.

	addition_interface = deftype () {
	  add = def (a:Self, b:Self) -> Self;
	}
	defop `common-infix + (left:addition_interface, right)
	  -> common.add(left, right)

arithmetic_interface: arithmetic on like objects with +, - (negate), -, *, /, % and ^ operators.

	arithmetic_interface = deftype () {
	  inherit addition_interface
	  negate   = def (a:Self) -> Self;
	  subtract = def (a:Self, b:Self) -> Self;
	  multiply = def (a:Self, b:Self) -> Self;
	  divide   = def (n:Self, d:Self) -> Self;
	  modulus  = def (n:Self, d:Self) -> Self;
	  exponent = def (b:Self, p:Self) -> Self;
	}
	defop `common-infix - (left:arithmetic_interface, right)
	  -> common.subtract(left, right)
	defop `prefix - (right:arithmetic_interface)
	  -> common.negate(left, right)
	defop `common-infix * (left:arithmetic_interface, right)
	  -> common.multiply(left, right)
	defop `common-infix / (left:arithmetic_interface, right)
	  -> common.divide(left, right)
	defop `common-infix % (left:arithmetic_interface, right)
	  -> common.modulus(left, right)
	defop `common-infix ^ (left:arithmetic_interface, right)
	  -> common.exponent(left, right)

equality_interface: test like objects for equality with == operator.

	equality_interface = deftype () {
	  isEqual = def (a:Self, b:Self) -> Boolean;
	}
	defop `common-infix == (left:equality_interface, right)
	  -> common.isEqual(left, right)

relational_interface: comparisons on like objects with ==, !=, >, <, >= and <= operators.

	relational_interface = deftype () {
	  inherits equality_interface
	  isGreater        = def (a:Self, b:Self) -> Boolean;
	  isLess           = def (a:Self, b:Self) -> Boolean;
	  isGreaterOrEqual = def (a:Self, b:Self) -> Boolean;
	  isLessOrEqual    = def (a:Self, b:Self) -> Boolean;
	}
	defop `common-infix != (left:relational_interface, right)
	  -> not common.isEqual(left, right)
	defop `common-infix > (left:relational_interface, right)
	  -> common.isGreater(left, right)
	defop `common-infix < (left:relational_interface, right)
	  -> common.isLess(left, right)
	defop `common-infix >= (left:relational_interface, right)
	  -> common.isGreaterOrEqual(left, right)
	defop `common-infix <= (left:relational_interface, right)
	  -> common.isLessOrEqual(left, right)

Previous: Prototypes ----- Up: Contents ----- Next: Numbers