MultiResult

Revision as of 18:03, 9 June 2018 by Lchrisman (talk | contribs) (Lchrisman moved page MultiReturn to MultiResult without leaving a redirect: Made a mistake with initial naming)

new to Analytica 5.2

Use this function when you want to return more than one distinct value from a User-Defined Function or expression. It is also sometimes convenient it certain looping scenarios when you want to set multiple local variables at the same time.

MultiResult( expr ... )

_( expr ... )

Accepts repeated expressions separated by commas, evaluates the only the ones that are captured by the caller or parent expression, and returns the results as multiple distinct return values. The dimensions of each return value are kept distinct -- they are not combined in any way. MultiResult(a,b,c) and _(a,b,c) are identical in functionality. Stylistically, the MultiResult(...) syntax is generally nicer when used for a UDF return value, whereas the _(...) lends itself to looping scenarios.

Examples

The following function returns the R, G, B and Alpha components of a color integer, as separate return values.

Function ColorComponents( c: Color ) :=
MultiResult(
BitAnd( [BitShift( c, 16), 0xFF] ),
BitAnd( [BitShift( c, 8), 0xFF] ),
BitAnd( [c, 0xFF] ),
BitAnd( [BitShift( c, 24), 0xFF] ) )

A caller could then capture the separate return values in local values using, e.g.,

Local (r,g,b,a) := ColorComponents( 'Turquoise' );

The next example illustrates its use in a looping construct. Here v is indexed by In1, and the «bodyExpr» does something where it requires v to be atomic, but it also needs to know the corresponding index value for that slice of v.

Local ( vi, i ) := _( v, In1);
«bodyExpr»


See Also

Comments


You are not allowed to post comments.