scan
The keyword scan
causes a process function to be applied to each line of a table in a specific order, resulting in a new vector.
‘proc(expr1) scan expr2’, ordering of the process
The scan
option can be applied to any Envision process to control the order of the operations over the processed table.
table T = with
[| as N, as L |]
[| 1, "b" |]
[| 0, "a" |]
[| 2, "c" |]
def process myConcat(t: text) with
keep txt = ""
txt = "\{txt}\{t}"
return txt
T.Asc = myConcat(T.L) scan T.N
T.Desc = myConcat(T.L) scan -T.N
show table "" with T.N, T.L, T.Asc, T.Desc
The show
statement results in the following table:
N | L | Asc | Desc |
---|---|---|---|
1 | b | ab | cb |
0 | a | a | cba |
2 | c | abc | c |
The first invocation of myConcat
follows the ascending ordering of T.L
’s elements according to T.N
: first "a"
, then "b"
, then "c"
. The computation proceeds as follows:
txt = "a"
txt = "ab"
txt = "abc"
For the second invocation of myConcat
, we follow the descending ordering: first "c"
, then "b"
, then "a"
. The computation proceeds as follows:
txt = "c"
txt = "cb"
txt = "cba"
The result of scan
in both cases is a vector containing all the intermediate results of the computation, using the order in which respective elements were handled.
It is also possible to specify auto
for the ordering, in which case the primary dimension of the table will be used. The primary dimension for table comprehension (table T = with
) will comprise of distinct ordinal values assigned to respective lines of the table; however, it is unspecified what those ordinal values will be. In general, using auto
for ordinal and enumeration types is considered a bad practice. For the sake of completeness, the following example demonstrates the use of auto
:
table T = with
[| as N, as L |]
[| 1, "b" |]
[| 0, "a" |]
[| 2, "c" |]
def process myConcat(t: text) with
keep txt = ""
txt = "\{txt}\{t}"
return txt
T.Aut = myConcat(T.L) scan auto
show table "" with T.N, T.L, T.Aut
As of Dec 7, 2024, the following table is produced:
N | L | Aut |
---|---|---|
1 | b | b |
0 | a | ba |
2 | c | bac |
However, the ordering of the elements in the Aut
column may change arbitrarily due to 1) a new version of Envision or 2) any change in the above script.