# Multilevel Parameters

esProc provides a large number of functions, many of which use multiple parameters. In order to clearly show the relationships between these parameters and streamline writing and reading, esProc is specially equipped with separators for presenting multilevel function parameters.

## 1.6.1 Function parameter separator

esProc uses colon (:), comma (,) and semicolon (;)as separators for function parameters. The priorities decrease in turn.

The most common practice is to use the comma to separate parameters, which is in line with the function syntax of most programming languages. For example:

 A B 1 Math 92 2 Writing 84 3 =if(B1>=80 && B2>=60,"Pass","Fail") 4 =create(Math,Writing,Result) 5 >A4.insert(0,B1,B2,A3)

In this example, parameters of if(), create() and T.insert() function in A3, A4 and A5 are separated from each other with commas. After the code in A3 is executed, the result of A4 is as follows: Some functions have parameters written in couple. They are closely related or work together. In this case, a colon is used between them.

 A B 1 Math 92 2 Writing 84 3 =if(B1+B2>=180:"A",between(B1+B2,150:180):"B", B1+B2>=120:"C",B1+B2<120:"D") 4 =create(Math,Writing,Rank) 5 >A4.insert(0,A3:Rank,B1:Math,B2:Writing)

For example, for if() function in A3, each condition corresponds to a returned result and colons are used to separate each pair of condition and result. In the between() function for specifying a condition, 150 and 180 are also separated by a colon but together they form a numerical interval [150,180]. In A5’s T.insert() function, field value and field name come in pairs with colons between them. After execution, A4’s result is as follows: In some functions, a demonstrative parameter follows a certain parameter to change the method of performing the operation based on the latter. In this case, a colon is used as the separator, as shown below:

 A 1 =demo.query("select * from CITIES") 2 =A1.sort(STATEID,NAME) 3 =A1.sort(STATEID,-NAME)

Both A2 and A3 sort records of cities according to state ID first, then cities of the same state by name. Difference is that the negative sign “-” is added before NAME in A3’s function to sort by name in reverse alphabetical order. The results of A2 and A3 are as follows:  Sometimes, parameters in a function can be divided into different parts according to their roles. Semicolons are used to separate these parts from one another.

 A 1 =demo.query("select * from CITIES") 2 =A1.groups(STATEID; sum(POPULATION):Population) 3 =A2.top(-5,Population,~)

In A2’s groups() function, the parameter before the semicolon is specified for grouping, and those after it are for aggregation. A colon is used between the two aggregation parameters to introduce the aggregate field name A2’s result is as follows: In A3’s top() function, the parameter before the comma defines that the top 5 records are fetched. The result is as follows: In some functions, parameters can be divided into several groups, which are separated by semicolons:

 A 1 =demo.query("select * from STATES") 2 =demo.query("select EID, NAME, STATE, DEPT, SALARY from EMPLOYEE") 3 =A2.groups(DEPT;count(~):Count) 4 =A2.switch(STATE,A1:NAME; DEPT,A3:DEPT)

T.switch() function in A4 transforms fields into records of different table sequences, and a semicolon is used to distinguish between the two groups. You can see that comma, colon and semicolon are all used in A4 as separators. This way of code writing creates clear layers for function parameters. The result in A4 is as follows: ## 1.6.2 Omission of function parameters

Some esProc function parameters have default values and, therefore, can be omitted, making functions more concise.

The parameter after a colon is generally used to further specify the operation performed with the other parameter. With default mode, the parameter can be omitted. For example:

 A B 1 Math 92 2 Writing 84 3 =if(B1>=80 && B2>=60,"Pass","Fail") 4 =create(Math,Writing,Result) 5 >A4.insert(0,A3:Result,B1:Math,B2:Writing) 6 >A4.insert(0,B1,B2,A3)

In A5, parameters after the colons are used to designate field names corresponding to values of the inserted records. Thus A6 can set field values directly according to the already specified field names without having to redefine them. After inserting two records respectively in A5 and A6, A4’s result is as follows: But colons cannot be omitted when they are used to represent intervals:

 A B 1 Math 92 2 Writing 84 3 =if(between(B1+B2,180:):"A",between(B1+B2,150:180):"B", between(B1+B2,120:150):"C",between(B1+B2,:120):"D")

In A3, between(B1+B2,180:) and between(B1+B2,:120) respectively mean B1+B2>=180 and B1+B2<=120, in which the colons cannot be omitted. A3’s result is as follows: In the cases where semicolon is required but the parameter which it expects to introduce doesn’t exist, the separator can be omitted. For example, if n is not set in A.top() function and only the top one is desired; or when the transformation of a certain field is not needed in T.switch() function.

A comma separator, however, should be retained even if the parameter following it is omitted. For example:

 A 1 [a,b,c,d,e,f,g] 2 =A1.to(4,) 3 =A1.to(,4)

Expression in A2 is equal to =A1.to(4,A1.len()), and expression in A3 is equal to =A1.to(1,4). Here’re the results of A2 and A3 respectively:  