calc()

Read(2625) Label: compute an expression, result,

Here’s how to use calc() function.

A . calc()

Description:

Compute an expression with one or more specified records and return a result.

Syntax:

A.calc(k,x)

Compute x against the kth member of A.

A.calc(p,x)

Compute x against the members of A specified by the integer sequence p.

Note:

The function computes an expression against one or more specified records and return a result.

Parameter:

A

A sequence/a record sequence.

x

An expression, which is generally a field name or a legal expression composed of field names, and "~" is used to reference the current record.

k

An integer specifying a record.

p

An integer sequence specifying multiple records.

Return value:

The result of x or a sequence composed of results of x.

Example:

Compute x against the kth member:

 

A

 

1

=[1,3,6,2,8]

 

2

=A1.calc(3,~*2)

12; compute expression "~*2" against the third member of sequence A1, "~" indicates the current member. The result is 12.

Compute x against the members of A specified by the integer sequence p:

 

A

 

1

=[1,3,6,2,8]

 

2

=A1.calc([4,3],~*2)

Compute expression "~*2" against the fourth and the third members of sequence A1 separately and the result is [4,12].

Do the computation against a table sequence:

 

A

 

1

=demo.query("select * from EMPLOYEE")

Return a table sequence.

2

=A1.calc(2,age(HIREDATE)+5)

Compute the number of years an employee works in the company according to hire date against the second record.

3

=A1.calc(A1.pselect@a(DEPT=="Administration"),

age(HIREDATE)+5)

Compute "age(HIREDATE)+5" against all the records whose DEPT is "Administration" and return the result as a sequence.