Efficiency question for list modification

Alex Tweedly alex at tweedly.net
Fri Mar 11 19:42:31 EST 2011


> FlexibleLearning wrote:
>
>> This is BAD...
>>    repeat for each line L in tData
>>      add 1 to n
>>      put (item 1 of L/div1) into item 1 of line n of stdout
>>      put (item 2 of L/div2) into item 2 of line n of stdout
>>    end repeat
>>
The use of "put ... after ..." is so efficient this may be an 
interesting but insignificant aside.

But ... it occurs to me there is another approach to this problem.

Use "split by column" to separate the two columns
Then use "split by row" to convert the columns into arrays
Then use  "divide <array> by <value>" to do the maths
Then combine them back again.

It's not (quite) as efficient for my simple test data as the other way, 
but I think it's an interesting way to use the newer form of the split 
command.

> on newway  @t, pCol1Divisor, pCol2Divisor
>    set the columnDelimiter to ","
>    set the rowDelimiter to CR
>    split t  by column
>    split t[1]  by row
>    divide t[1] by pCol1Divisor
>    combine t[1] by row
>    split t[2] by row
>    divide t[2] by pCol2Divisor
>    combine t[2] by row
>    combine t by column
> end newway

-- Alex.





More information about the use-livecode mailing list