esProc Getting Started: Multilayer Parameters

esProc 926 0

esProc provides a large number of functions, many of which use many parameters. In order to clearly judge the positions of these parameters and make writing and reading easier, esProc is specially equipped with multilayer separators of function parameters.

1. Separators of function parameters

Colon (:), comma (,) and semicolon (;) are used as separators of function parameters in esProc. Their priority decreases in turn.

The most common method is to use commas to separate parameters, which is in line with function syntax in 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 by commas. After the code in A3 is executed, the result of A4 is as follows:

esProc_start_parameters_2

Some functions have “coupled” parameters, which are closely related or work together. In this case, a colon is often used to separate them.

  A B
1 Math 92
2 Writing 84
3 =if(B1+B2>=180:”A”,in(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 the results. In the in() function used in a condition, 150 and 180 are also separated by a colon and together they form a numerical interval [150,180]. In A5’s T.insert() function, field value and field name also come in pairs with colons in between to separate them. After execution, the result in A4 is as follows:

esProc_start_parameters_4

In some functions, indicative parameters can be added to certain parameters to change the computational method relating to them. In this case, colons are usually used as separators. See below:

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

Both A2 and A3 sort records of cities according to state ID first, then sort by name if cities belong to the same state. Difference is that -1 is appended after NAME in A3’s function, meaning that sorting by name is in a descending order. The results in A2 and A3 are as follows:

esProc_start_parameters_6

Sometimes, parameters in a function can be divided into different parts according to their roles. Semicolons are usually used to separate these parts.

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

In A2’s groups() function, the parameter before the semicolon is used for grouping, and those after it are for summarizing computation, whose parameters are separated by a colon to define name of the summarizing field. The result in A2 is as follows:

esProc_start_parameters_8

In A3’s top() function, the parameter after the semicolon defines that the top 5 records are fetched. The result is as follows:

esProc_start_parameters_9

In some functions, parameters are quite many. Usually these parameters are 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 different fields into records of another table sequence, and a semicolon is used here. Besides, comma, colon and semicolon are all used in A4 as separators. This kind of code writing creates clear layers for function parameters. The result in A4 is as follows:

esProc_start_parameters_11

2. Omission of function parameters

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

The parameter after a colon is generally used to complement another’s computational model. If default mode is used, 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 certain values when inserting records. Parameters for designating field names can be omitted in A6 because they use default field names to set field values one by one. Two records are inserted respectively in A5 and A6, then the result in A4 is as follows:

esProc_start_parameters_13

But colons cannot be omitted when they are used to separate intervals:

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

In A3, in(B1+B2,180:) and in(B1+B2,:120) represent respectively B1+B2>=180 and B1+B2<=120, in which the colons cannot be omitted. The result in A3 is as follows:

esProc_start_parameters_15

For parameters separated by semicolons, the semicolon can be omitted if there is no parameter after it. For example, if n is not set in A.top() function and only the top one is needed; or when the transformation of a certain field is not needed in T.switch() function.

When commas are used as separators, they should generally be retained if parameters are set by default. 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()), expression in A3 is equal to =A1.to(1,4). Let’s compare the results in A2 and A3:

esProc_start_parameters_17

FAVOR (0)
Leave a Reply
Cancel
Icon

Hi,You need to fill in the Username and Email!

  • Username (*)
  • Email (*)
  • Website