In Shang, function is a facet of almost any data type, therefore almost anything
can be used as a function. In particular,
- If A is a number or matrix, then A(x) = A * x.
- If A is a hash table and x is a key, then
A(x) = A @ x.
- If A is a set, then A(x) = 1 if x is in A,
and 0 if x is not in A.
- If A and B are strings, then A(B) is non-zero if
A is a substring of
B, and zero otherwise.
- If A, and x are two lists with the same length, then
- If A is a regular expression and B is a string, then A(B) is non-zero if
B matches A and zero otherwise.
- If A is a class, then A(x) is non-zero if x is a
member of
A,
and zero otherwise.
- If A is an member of a class that has multiplication operator
overloaded, A(x) = A * x.
For example, the function
can be created by f = (5, -3),
while
the function
can be created by
f = {0 => 1, 1 => 2, 2 => 3, 3 => 4, 4 => 5, 5 => 0};
oz
2009-12-22