Making the move...

Alex Tweedly alex at
Wed Mar 22 05:12:57 EST 2006

Sarah Reichelt wrote:

>OK, I have a better example. Say I have a data set and I need to loop
>through it and extract three different pieces of information e.g. a
>list of the 4th column in each line, a list of lines that match a
>certain set of criteria, and a cumulative total obtained by adding a
>certain column in each line.
>Each of these could be done in a separate function, but that would
>mean looping through the data set three times. With a large data set,
>it is significantly faster to loop once, filling all three new
>variables in the single loop. If I separate this off into a separate
>function, then I need a way of passing multiple results back.
>The alternatives that I see are to use script local variables or to
>pass an empty parameter by reference and have the function fill it.
>Does anyone have any other ideas or recommendations?
I'd probably use parameters by reference for each of the result values. 
To me, that's one of the good ways to use pass by ref.

But if you didn't want to do that, and also didn't want to use an array, 
you could perhaps return a list of the result values. If you can find 
one more character that you can be sure won't appear in the results, 
simply use it to concatenate the results.

For example:

> function getThreeThings pFrom
>    .....
>  return tOne & numtochar(3) tTwo & numtochar(3) & tThree
> end getThreeThings

and when you call it

>     put getThreeThings(tData) into temp
>     set the itemDel to numtochar(3)
>     put item 1 of temp into t1
>     put item 2 of temp into t2
>     etc.

btw - when are Rev going to implement the "etc." keyword ?

Alex Tweedly

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.385 / Virus Database: 268.2.6/286 - Release Date: 20/03/2006

More information about the Use-livecode mailing list