|
|||||
|
|||||
Prerequisite Concepts | Related Syntax | ||||
Functions: infix |
Infix functions are functions that work like operators. That is, the name of the function goes between its two arguments, just as the +
symbol goes between the two values to be added. In fact, an operator and an infix function are really two different names for the same thing. You can create an operator, therefore, by defining an infix function.
Here is an example of an infix function that calculates the distance between two points. It uses the symbol ">>>" to represent the concept of distance. The points are represented by records.
import "omfloat.xmd" unprefixed declare record point field float x field float y define float infix-function value point a >>> value point b as return sqrt(((a:x - b:x) ** 2) + ((a:y - b:y) ** 2)) process local point Ghent local point Aix set Ghent:x to 137.5 set Ghent:y to 83.2 set Aix:x to 219.7 set Aix:y to 345.9 output "d" % Ghent >>> Aix
Prerequisite Concepts Functions |
Related Syntax define infix-function |