diff()

Read(5277) Label: first, remove, difference,

Description:

Calculate difference between the sequence-type members in a specified sequence.

Syntax:

A.diff(x)

Note:

The function computes difference between sequence-type members in sequence A, ensuring that members of the new sequence do not include any member of the other sub-sequences. When parameter x is present, compute expression x with each member of A and then find the difference.

 

The algorithm is to compute the difference between the first sub-sequence and the second one, then compute the difference between the result and the third sub-sequence, and so on and so forth.

Parameter:

A

A sequence whose members are sequences

x

An expression that returns a sequence; cannot be omitted when members of A are table sequences or record sequences

Return value:

A sequence

Example:

When A is a sequence:

 

A

 

1

=[[1,2,3,4,5],[3,7,8]].diff()

[1,2,4,5]

2

=[[1,2,3],[3,2],[1]].diff()

[]

3

=[[1,2,2,3],[2]].diff()

[1,2,3]; delete a duplicate member once only

When A is a table sequence or a record sequence:

 

A

 

1

=demo.query("select * from STUDENTS where ID>3")

2

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

3

=[A1,A2].diff(~.(NAME))

["Michael","John","Nicholas"]