On 15 Mar 2007, at 04:53, Mark Wieder wrote:

Richard-

Wednesday, March 14, 2007, 8:54:34 AM, you wrote:

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.

Aw, that's nothin' - I got 2,360,000 hits from Google looking up
Hashtable, which is another way of saying "associative arrray".

Yes, it's really all down to implementation. For instance SNOBOL4/ SPITBOL implements Both Arrays and Associative Arrays (called tables) as so:

Both "[]" and "<>" can be used to hold the array index or table key. By convention "[]" is used for Arrays and "<>" is used for tables.

A Table (Associative Array) is setup as so:

  myTable = table(100,50)

Which creates a table with 100 pre-allocated entries and when this is full, will extend the table by 50 entries.

A table is accessed as so:

  myValue = myTable<"key">

 myTable<"key"> = myValue


An Array (Bounded Index Array) is setup as so:

  myArray = array("-100:100,200:900")

Which creates a 2D array with indexes 200 entries in X (addressed as -100 to +100) and 700 entries in Y (addresses as +200 to +900).

An Array is accessed as so:

 myValue = myArray[-7,489)

myArray[-7,489) = myValue

If an attempt is made to access an out of bounds item a run-time error occurs (an exception is thrown).

There are functions to convert between Arrays and Tables, such as:

myArray = convert(myTable,"array") Which creates a 2D array from myTable

myTable = convert(myArray,"table") Which creates a Table from the first two dimensions of an array.

There are more specialized functions too, such as:

myArrayA = sort(myArrayB,index) Which sorts an array into another array using the dimension specified by index as the sort field.

myArray = sort(myTable,index) Which sorts a table into an array using either the key or the data field as the sort field.

This allows both data types to co-exist and work together and believe me it's Super-Powerful!

If Index type arrays were implemented in RunRev, I'm not sure how the syntax would work, how would the compiler/interpreter know that:

myArray[1,2] didn't mean key "1,2" or vice versa, also how would the bounds of the array be checked?

All the Best
Dave












_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to