Difference between revisions of "Iterator.run"
m (Created page with "== Calling Pattern == Call local i = sl.iterator(a,b[, c[,...]]) -- later local r = i.run(arg[, ...]) Args arg0..argN are variadic arguments of any type Results r is a table...") |
m (→Description) |
||
Line 13: | Line 13: | ||
== Description == | == Description == | ||
− | Run supplies each key and value in a to b in turn, as well as all static arguments (c0... | + | Run supplies each key and value in a to b in turn, as well as all static arguments (c0...cM) passed to the iterator constructor, as well as all run arguments (arg0...argN). E.g.: |
− | r_i = b(akey_i,aval_i,c0..., | + | r_i = b(akey_i,aval_i,c0...cM,arg0...argN) |
− | r = { | + | r = {r1, ... ,rI} |
+ | |||
+ | Run iterates over all key value pairs of table a until depleted unless b returns a special value, [[null]], in which case the run is terminated at that point. | ||
+ | |||
+ | If the keys in table a are contiguous numeric indices, they will be iterated over in ascending order. Order cannot be controlled with non-numeric keys, or when there are gaps in numerical keys. | ||
+ | |||
+ | If b was a table of functions, then run iterates over all key value pairs of table a as described above, with each function value of table b being called in an inner loop. E.g.: | ||
+ | |||
+ | r_ij = b_j(akey_i,aval_i,c0...cM,arg0...argN) | ||
+ | r = {r_1_1...r_1_J, ... ,r_I_1...r_I_J} | ||
== Upon Error == | == Upon Error == |
Revision as of 18:24, 24 November 2010
Calling Pattern
Call
local i = sl.iterator(a,b[, c[,...]]) -- later local r = i.run(arg[, ...])
Args
arg0..argN are variadic arguments of any type
Results
r is a table
Example Usage
Description
Run supplies each key and value in a to b in turn, as well as all static arguments (c0...cM) passed to the iterator constructor, as well as all run arguments (arg0...argN). E.g.:
r_i = b(akey_i,aval_i,c0...cM,arg0...argN) r = {r1, ... ,rI}
Run iterates over all key value pairs of table a until depleted unless b returns a special value, null, in which case the run is terminated at that point.
If the keys in table a are contiguous numeric indices, they will be iterated over in ascending order. Order cannot be controlled with non-numeric keys, or when there are gaps in numerical keys.
If b was a table of functions, then run iterates over all key value pairs of table a as described above, with each function value of table b being called in an inner loop. E.g.:
r_ij = b_j(akey_i,aval_i,c0...cM,arg0...argN) r = {r_1_1...r_1_J, ... ,r_I_1...r_I_J}
Upon Error
If a non-function (or table with a non-function entry) was passed to the iterator constructor as the second argument, then an error will be raised when it is encountered during run(). Error is reported and handled according to the operant error redirection mode.