Skip to content

over, scan

Wrappers for the Over and Scan iterators

The keywords over and scan are wrappers for the accumulating iterators, Over and Scan. Prefer over and scan with unary and binary values.

Like Over and Scan, over and scan share the same syntax and perform the same computation. scan returns the result of each evaluation; over returns only the last.

Converge

 v1 over x    over[v1;x]        v1 scan x    scan[v1;x]
(vv)over x    over[vv;x]       (vv)scan x    scan[vv;x]

Where

applies the value progressively to x, then to v1[x] (or vv[x]), and so on, until the result matches (within comparison tolerance) either

  • the previous result, or
  • x
q)n:("the ";("quick ";"brown ";("fox ";"jumps ";"over ");"the ");("lazy ";"dog."))
q)raze over n
"the quick brown fox jumps over the lazy dog."
q)(,/)over n
"the quick brown fox jumps over the lazy dog."
q){x*x} scan .01
0.01 0.0001 1e-08 1e-16 1e-32 1e-64 1e-128 1e-256 0

For more detail, and for the related forms Do and While, see Accumulators.

MapReduce, Fold

v2 over x   over[v2;x]        v2 scan x   scan[v2;x]

Where v2 is a binary applicable value, applies v2 progressively between successive items.

scan[v2;] is a uniform function and over[v2;] is an aggregate function.

q)(+) scan 1 2 3 4 5
1 3 6 10 15
q)(*) over 1 2 3 4 5
120

Keywords

Several q keywords are common projections of scan and over. For example, sums is scan[+;] and prd is over[*;].

For efficiency and good q style, prefer these keywords; for example, use prd rather than over[*;] or */.

keyword  equivalents
---------------------------------------
all      over[and;]   &/  Lesser Over
any      over[or;]    |/  Greater Over
max      over[|;]     |/  Greater Over
maxs     scan[|;]     |\  Greater Scan
min      over[&;]     &/  Lesser Over
mins     scan[&;]     &\  Lesser Scan
prd      over[*;]     */  Multiply Over
prds     scan[*;]     *\  Multiply Scan
raze     over[,;]     ,/  Join Over
sum      over[+;]     +/  Add Over
sums     scan[+;]     +\  Add Scan

Accumulators