2 dimensional Arrays

Richard Gaskin ambassador at fourthworld.com
Wed Mar 14 12:54:34 EDT 2007


Dave wrote:
> The problem is that "arrays" in RunRev are not "arrays" in the same  
> sense as in languages like C/C++ or Pascal etc. They are really look  
> up tables. 

For the benefit of newcomers here, it may be worth noting that 
associative arrays are hardly an invention of Rev's:

<http://www.google.com/search?q=associative+arrays>

So while it's true that Rev's arrays are associative rather than 
numerically indexed (and a request has been submitted to make that more 
self-evident in the docs), it's not like Rev invented some novel form of 
array.  As the 800,000 hits at that link show, associative arrays are a 
common feature of a great many languages.

The upside of associative arrays is that the syntax for using them is 
pretty much identical to how one would expect to use a 
single-dimensional numeric array, while also allowing non-numeric keys.

The downside occurs in those cases where a multi-dimensional numeric 
array is desired, which your function addresses well:

> In RunRev instead of passing an index (or indexes) to  
> retrieve the data for an entry you pass a key. You can fake the way  
> Arrays work in languages like C/C++ etc, by passing key values such  
> as "1,5", but this is actually passing a three character key of "1"  
> "," "2".
> 
> I've found that if you are using the key section in a non-trivial way  
> (like in the 2D array example) it's better to use a function that  
> returns your munged key for you, e.g. something like this:
> 
> function Get2DArrayKey theIndex1,theIndex2
> 
> return theIndex1 & "," & theIndex2
> end
> 
> and to use:
> 
> put "xxxx" into my2DArray[Get2DArrayKey(1,5) ]
> 
> or
> 
> put  my2DArray[Get2DArrayKey(1,5)] into myValue
> 
> 
> If you *ALWAYS* use this function, you will always get consistent  
> keys, otherwise you may have the problem you described where it's  
> starts to get confusing because of extra quote characters, etc.

-- 
  Richard Gaskin
  Fourth World Media Corporation
  ___________________________________________________________
  Ambassador at FourthWorld.com       http://www.FourthWorld.com



More information about the use-livecode mailing list