1. esProc’s function options
Many functions in esProc can use function options with which the same function can have different work patterns. The basic format of function options is f@o(…) in which o is f function’s option. For example:
We can use interval function to compute the days between two dates. In expressions in A3 and A4, @y and @m are interval function’s options. With these options, the function will use the year and the month as computational units in computing time interval. With function options, a function can meet multiple needs, extend its functions and avoid too many function names or function parameters.
2. Common function options
Some function options are common in esProc. They can be used by many functions.
- @1 and @a
@1 option and @a option are frequently used by functions to position, select and join, such as, A.pos(), A.select(), A.pmax(), A.pselect(), A.minp(), P.align(), etc.
Use of @a option can make functions that return the first query result by default return all eligible results. Contrary to @a, functions that return multiple members by default will return only the first query result by using @1 option.
We’ll look at the use of these two options through some examples:
By the way, since digit 1 is difficult to distinguish from the lowercase letter l, in most cases, the former is used in esProc’s options.
One other thing need to be made known is that the same option in different functions can have different meanings. For example, @a used in position functions means returning all results, while in functions for file writing, like f.write() and f.export(), it means appending.
@z option is often used in some functions relating to order, like sort, position, select, etc. Such as A.rank(), A.sort(), A.pos(), A.pselect(), A.select() and so on.
With @z option, position or select in a sequence or a table sequence will be executed from back to front. Thus in this example, A2 returns the position of the last 2 and A3 returns results of sorting in descending order. Records obtained by A5 are also sorted in descending order.
@b option is often used in functions to position, select, etc., like A.pos(), A.pselect(), A.select(), and so on. The use of @b option is usually accompanied by binary search algorithm, which is more efficient, in query, with the prerequisite that A is ordered; otherwise results may be wrong.
Since data in A1 are not sorted according to state ID, only one result is obtained with the binary search method when @b option is used in A2; while A4 obtains the correct results because data are sorted in A3.
But it is another thing when @b is used in functions to read and write, such as f.import(), f.export(), f.cursor(). In this case, it is the binary files that being read in or written out. In esProc, binary files have smaller storage size and faster access speed, therefore the use of binary files will bring higher efficiency.
- 3 Simultaneous use of multiple options
Multiple options can be used simultaneously in esProc when needed. There is no particular order among these options. For example:
Because both A 2 and A3 get positions of all the 2 in A1 from back to front, their results are identical. A5 gets the first city whose state ID is 5 from back to front.
Note that some function options are contradictory to each other, and cannot appear simultaneously. Such as @a and @1, @t and @b options of f.import().