Sequence

Read(232) Label: sequence,

This chapter lists code examples of handling sequences, including Check if it is a sequence, Get a sequence member or a sub-sequence in reverse direction, Get a sequence member or a sub-sequence in cycles, Get a sub-sequence but report no error if a specified position is beyond range, Get the first non-null value, Generate a fixed-length sequence consisting of duplicate members, Duplicate a sequence (repeatedly) to generate a new sequence, Generate a continuous interger sequence, Exchange positions of member groups of a sequence, Insert one or multiple members to a sequence, Delete one or multiple members from a sequence, Modify one or multiple members of a sequence, Modify sequence member(s) at specified position(s) and supply values at the beyond-range position(s), Insert a sequence as a member into another sequence, and Compare sequences in ASCII dictionary mode.

Check if it is a sequence

 

A

 

1

=ifa([1,2,3])

true

2

=ifa(123)

false

 

Get a sequence member and a sub-sequence in revers e direction

 

A

 

1

=[1,2,3,4,5,6].m(-3)

4

2

=[1,2,3,4,5,6].m([-2,-3])

[5,4]

 

Get a sequence member or a sub-sequence in cycles

 

A

 

1

[1,2,3,4,5,6]

 

2

=A1.m@r(10)

4

3

=A1.m@r([1,5,10])

[1,5,4]

 

Get a sub-sequence but report no error if a specified position is beyond range

 

A

 

1

=[1,2,3,4,5,6].m@0([10,1,4,5])

The result is [1,4,5] where out-of-range members do not appear

 

Get the first non-null value

 

A

 

1

=[null,1,5,7].ifn()

1

 

Generate a fixed - length sequence consist ing of same members

 

A

 

1

=5*[1]

[1,1,1,1,1]

2

=3.("a")

[a,a,a]

 

Duplicate a sequence ( repeatedly ) to generate a new sequence

 

A

 

1

=[1,2,3]

 

2

=A1.to()

[1,2,3]

3

=3*A1

[1,2,3,1,2,3,1,2,3]

Generate a continuous integer sequence

 

A

 

1

=to(8)

[1,2,3,4,5,6,7,8]

2

=to(3,5)

The result is [3,4,5] which is from 3 to 5

3

=to@s(3,5)

The result is [3,4,5,6,7] which counts 5 numbers forward from 3

4

=to@s(7,-3)

The result is [7,6,5]

 

Exchange positions of member groups of a sequence

 

A

 

1

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

[1,6,7,5,2,3,4,8]

 

Insert one or multiple members to a sequence

 

A

 

1

=[1,2,3,4].insert(0,5)

[1,2,3,4,5]. Insert the members at the end

2

=[1,2,3,4].insert(1,5)

[5,1,2,3,4]. Insert the members at the beginning

3

=[1,2,3,4].insert(3,[5,6])

[1,2,5,6,3,4]. Insert multiple members

 

Delete one or multiple members from a sequence

 

A

 

1

=[11,12,13,14].delete(2)

Delete one member and the result is [11,13,14]

2

=[11,12,13,14].delete([2,4])

Delete multiple members and the result is [11,13]

 

Modify one or multiple members of a sequence

 

A

 

1

=[11,12,13,14]

 

2

>A1(2)=6

The value in A1 is [11,6,13,14]

3

>A1([3,4])=[7,8]

The value in A1 is [11,6,7,8]

 

Modify sequence member (s) at specified position (s) and supply values at beyond-range position (s)

 

A

 

1

=[11,12,13,14,15].modify(2,6)

[11,6,13,14,15]

2

=[11,12,13,14,15].modify(10,10)

[11,12,13,14,15,null,null,null,null,10]

3

=[11,12,13,14,15].modify(2,[7,8,9])

[11,7,8,9,15]

 

Insert a sequence as a member into another sequence

 

A

 

1

[1,2,3,4]

 

2

[5,6,7,8]

 

3

=A1.insert(3,[A2])

[1,2,[5,6,7,8],3,4]

 

Compare sequences in ASCII dictionary mode

 

A

 

1

=cmp(["a","b","c"],["d","e","f"])

-1, ASCII code for "a" is 1 less than that for "d"

2

=cmp(["d","b","c"],["a","e","f"])

1, ASCII code for "d" is 1 more than that for "a"