returning result from a function when the number of items in the result varies

Richard Gaskin ambassador at fourthworld.com
Sat Sep 20 22:58:09 EDT 2008


william humphrey wrote:

> for some reason in my function if I say
> 
> return myArray then I get an array with zero lines even when that is not
> true.
> 
> If I say return myArray[1]  (where 1 is one of the keys which has data in
> the array) then it does return that correctly but just with that one line of
> course.
> 
> This is why I hate arrays. It is not working like I expected.

Then maybe just consider a simple delimited list instead.

Arrays are way cool for a great many things, but they're not the answer 
to every problem.  Your data set is small enough that the specific 
operations that arrays excel at will have no noticeable performance 
difference doing them with a simple list.

Extra bonus points for lists in your case:  you can simply put the 
variable into a field, without having to run it through the combine 
command first.

For small data sets performance won't matter much either way. But for 
large collections of things, the split and combine commands are very 
computationally expensive. Because they're effectively parsing and 
delimiting the data entire set, they're really only doing what you can 
do yourself with "repeat for each" but without the extra step.

For random access of specific elements, the efficient internal hashed 
representation of keys makes accessing array elements several orders of 
magnitude faster than any method for finding lines in a list.  But if 
you're not doing frequent random access the tradeoffs become the sort of 
thing where there is no best answer, it really depends on what you're doing.

In your case your data set is small, so you have the luxury of doing 
whatever feels most comfortable.  Have fun!

-- 
  Richard Gaskin
  Managing Editor, revJournal
  _______________________________________________________
  Rev tips, tutorials and more: http://www.revJournal.com



More information about the use-livecode mailing list