Difference between revisions of "Iterator.run"

From OpenEUO
Jump to: navigation, search
m (Description)
m (See Also)
 
(2 intermediate revisions by the same user not shown)
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...cM) passed to the iterator constructor, as well as all run arguments (arg0...argN). E.g.:
+
Run supplies each key and value in a to b in turn, as well as all variadic 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_i = b(akey_i,aval_i,c0...cM,arg0...argN)
Line 36: Line 36:
  
 
* [[case]]
 
* [[case]]
 +
 +
* [[iterator]]
  
 
* [[spin]]
 
* [[spin]]
Line 41: Line 43:
 
* [[chain]]
 
* [[chain]]
  
* [[statemachine]]
+
* [[machine]]

Latest revision as of 21:50, 15 July 2012

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 variadic 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.

See Also