FutureBasic Logo

<<    Index    >> FutureBasic

mda   statement / function



Statement syntax
mda [tag] ( dim1 [, dim2 [, ... ] ] ) = { object | intValue | dblValue }

Function syntax
{ object | intValue | dblValue } = mda [tag] ( dim1 [, dim2 [, ... ] ] )

Note: the tag parameter identifies which array to use. If it is omitted, array 0 is used.

 
Description
Although mda is an acronym for "multi-dimensional array", mda arrays can also be single-dimensional.

The mda statement assigns value to an element in one of FB's special mda arrays. mda arrays are mutable, single or multi-dimensional, always global in scope and are zero-based. An mda array contains CF/NS objects. However, for convenience, integer and double values can be used directly in its statements/functions and are converted to/from objects behind the scenes.

You can read the contents of an mda array element by using the mda function.

Your program can use as many mda arrays as memory allows, numbered -2,147,483,648 through 2,147,483,647. The tag parameter specifies which mda array to use. If you omit this parameter, mda 0 is used. The dim1, dim2, ... parameters specify which element to target in the array.

More options
Option Description
mda_add [tag] ( dim1 [, dim2 [, ... ] ] ) = { object | intValue | dblValue } Adds a value to the end of the array
Note: If the number of dims entered is equal to the array's dim count, the last dim value is ignored
mda_clear [tag] Removes all elements from the array
mda_count [tag] ( dim1 [, dim2 [, ... ] ] ) = count Returns the length of the array at the specified location
string = mda_description [tag] [, includeEmptyArrays [, includeNullValues ] Useful for debugging. Returns a string description of the contents of the array
The optional includeEmptyArrays and includeNullValues flags default to YES.
dblValue = mda_double [tag] ( dim1 [, dim2 [, ... ] ] ) Force mda to return a double value (see Limitations below)
mda_insert [tag] ( dim1 [, dim2 [, ... ] ] ) = value Inserts value at the specified location
intValue = mda_integer [tag] ( dim1 [, dim2 [, ... ] ] ) Force mda to return an integer value (see Limitations below)
mda_kill [tag] Deletes the entire array
object = mda_object [tag] ( dim1 [, dim2 [, ... ] ] ) Force mda to return an object value (see Limitations below)
[flag = ] mda_read [tag,] url Reads an mda array from a previously saved file at the specified url. Returns YES if successful
mda_remove [tag] ( dim1 [, dim2 [, ... ] ] ) Removes the value at the specified location
mda_remove_nulls [tag] Removes all NULL values from the array
mda_sort [tag] [, selector] Sorts the entire array in ascending order. Note: This has the effect of removing all NULL values

The optional selector parameter must be a CFString literal and can have one of the following values:
@"compare:" (default)
@"caseInsensitiveCompare:"
@"localizedCaseInsensitiveCompare:"
@"localizedCompare:"
@"localizedStandardCompare:"

mda_swap [tag1] ( dim1 [, dim2 [, ... ] ] ), [tag2] ( dim1 [, dim2 [, ... ] ] ) Swaps the values at the specified arrays and locations
string = mda_text [tag] Returns the textual contents of the array
[flag = ] mda_write [tag,] url Writes the mda array to a file at the specified url. Returns YES if succesful
 

Aggregate initialization
Say what?... "Aggregate initialization" is just a fancy name for "shortcut population". For example, the following line assigns the values 1-9 to the first nine elements of a single-dimensional array.

mda (0) = {1,2,3,4,5,6,7,8,9}

The next example populates a two-dimensional array. Note the nested curly braces.

mda (0,0) = {{@"a",@"b",@"c"},{@"d",@"e",@"f"},{@"g",@"h",@"i"}}
print mda_text

Output:
a	b	c
d	e	f
g	h	i

And finally, a three-dimensional array

mda 2(0,0,0) = {{{10,11},{12,13}},{{14,15},{16,17}},{{18,19},{20,21}}}
print mda_text 2

Output:
10	11	
12	13	
14	15	
16	17	
18	19	
20	21	

 

Limitations
Some things we cannot (yet) do with mda arrays
 
(1) mda 1(2) = mda 1(0) + mda 1(1) // fail

Workaround - use CFNumber literal syntax '@()' around the expression
mda 1(2) = @(mda 1(0) + mda 1(1))

 
(2) if ( mda 1(0) == 12 ) then beep// fail

Workaround - force an integer return value by using the mda_integer keyword
if ( mda_integer 1(0) == 12 ) then beep

 
(2) printf @"%@", mda 1(0)// fail

Workaround - force an object return value by using the mda_object keyword
printf @"%@", mda_object 1(0)