Arrays vs Lists

Dar Scott dsc at
Wed Dec 4 13:46:01 EST 2002

On Wednesday, December 4, 2002, at 06:32 AM, Mike McManus wrote:

> I have seen a lot about arrays lately here. So I am wondering.
> 1. Why or when is an Array better than a list?

Use a list when...
1.  You think of the data as a sequence.
2.  You might sometimes want to get the nth one, but not often for big 
3.  You might want to peak at it (debugging or otherwise).
4.  You might want to easily add an item to either end.
5.  You might want to combine the data to make a new sequence with one 
after the other.
6.  You don't need items to be binary data or arbitrary numbers.

Use an array when...
1.  You want to name or number each entry.  (The numbers are really 
2.  You don't think of any order except as how you order keys.
3.  You sometimes want to do something to all elements (ignoring keys)
4.  You might have a large number of key-element pairs and want to look 
them up quickly.
5.  You might store data that might have delimiters in it.
6.  You might store data that is a number in a calculation.

This applies whether "list" means items in a line or lines in a value.

> 2. When is a multidimensional Array better than a variable made up of 
> multiple lines with a list on each line?

Hmmmm.  I'm not sure how Revolutionaries use the word "list".  The chunk 
goes up from char, word, item and line.  You can use that to structure 
your data.  (The doc says a word can be a quoted phrase, but I haven't 
tried it.)  The most important limitation is data that includes quotes 
or your delimiters (ordinarily spaces, commas and lineFeeds).

If you put a number into such a string, it will be converted using 
numberFormat, so you can lose data.

With an array the key is forced to be a string.  You can think of pairs 
as automatically sorted by keys.  The element can be an internal number 
(preserving large and small exponents), but cannot be another array.  If 
you use a number in an element in a way that requires a string, then 
numberFormat is used at that time.  This includes combine.

You can combine these methods.

Now I have a question for all.  In the Revolution culture, what does 
"list" mean?  Items separated by commas?  lines?  Or something more 
general and abstract?

Dar Scott

More information about the Use-livecode mailing list