• esProc
Tutorial
Function Reference
User Reference
External Library Guide
Data File Tool Manual
DQL Tutorial
Cluster Server Manager Manual
SPL WIN Manual
• YModel
User Reference
JSON-style Parameter Guide
• ReportLite
User Reference
• Official Website

# The writing rules for expression x in loop functions

Description:

Introduce the common rules on expressions in loop functions.

Note:

Expression x in loop functions such as r.(x), r.run(x), A.(x), A.run(x) and so on, should follow the rules below:

1. Members: ~ and A.~. ~ means the record being processed currently.

 A 1 =demo.query("select * from EMPLOYEE") 2 =A1.(age(~.HIREDATE)) [9,6,3,7,9,8,…] 3 =A1.new(~.NAME:Name,age(~.HIREDATE):Workage)

2. Ordinal numbers: # and A.#. # indicates the ordinal number of the members.

 A [1,2,3,4,5,6,7,8…], the two results are the same. 1 =demo.query("select * from EMPLOYEE") 2 =A1.(#) 3 =A1.(A1.#)

3. Fields: F, ~.F, r.F and A. F are equal to A.~. F , and A.F is equal to A(1).F if there is not a loop.

 A 1 =demo.query("select * from EMPLOYEE") 2 =A1.(age(HIREDATE)) 3 =A1.(age(~.HIREDATE)) Same result as A2. 4 =A1.(age(A1.HIREDATE)) Same result as A2. 5 =A1.HIREDATE 2005-03-11, it is equal to A1(1).HIREDATE if there is not a loop.

4. A[i] and ~[i] are equal to A(#+i) in the loop, which counts the members forward from the current member in A.

5. Return the ith member and if the boundary is exceeded, errors are not reported and null is returned. F[] is equal to A[].F.

 A 1 =demo.query("select ORDERID,AMOUNT,'' as ACCUMULATION from SALES") 2 =A1.run(ACCUMULATION=AMOUNT+ACCUMULATION[-1]) Obtain the current ACCUMULATION by adding the ACCUMULATION of the last record to the current AMOUNT.

6. A[a:b] and ~[a:b] in the loop indicate a sequence composed of members between A(#+a) and A(#+b).

7. Return a sequence consisting of members within the specified interval. a is 1-# by default and b is A.len()-# by default.

 A 1 =demo.query("select STOCKID,DATE,CLOSING,'' as FirstThree from STOCKRECORDS") 2 =A1.run(FIRSTTHREE=~[--3:-1].(CLOSING).avg()) ~[-3:-1] indicates a sequence composed of three records counted backward from the current row.

8. Iteration: A1.f1(A2.f2(x))

Symbols in expression x will be first identified to serve A2; if expression x serves A1, the iteration will be . A1.f1(A2.f2(A1.x)).

 A 1 =demo.query("select * from EMPLOYEE") 2 =demo.query("select * from DEPARTMENT") 3 =A2.run(MANAGER=A1.select@1(EID==A2.~.MANAGER).NAME) Reference the nested loop.

9. Aggregate: A.f(x)

A.f(x) is equal to A.(x).f(), in which f is an aggregate function and x can be null.

Note: The x in A.count(x) is a Boolean expression, which is different from the rule for other aggregate functions.

10. get(level,F;a:b)

Get information of base members at a superior level in a multilayer loop function

 A 1 [1,2,3] 2 =A1.(A1.(abs(~-get(1)))) Calculate the maximum distance from each value to the others. 3 =demo.query("select * from employee") 4 =A3.derive(A3.max(abs(SALARY-get(1,SALARY))):MaxDiff) Calculate the maximum salary difference for each employee compared with every other employee.