heehee invented Map literals in ASH, and a fine feature they are. A little while ago, I made them a Value, and just now I allowed them to appear on the right hand side of an Assignment.
You could (and can) use them in function calls:
And you could (and can) use them to initialize a mp:
And revision 17910 lets you put in an '=' like so to make them look like any other assignment for variable initialization:
And that made me consider allowing simplified syntax if the type of the AggregateLiteral is actually an Array.
We currently can do this:
yielding this:
Notice that an array is interchangeable (syntax-wise) with a map whose key is an int - except obviously you can't create arbitrary new indices in an array.
I propose the following:
We can do this:
If the Type of the Aggreate on the LHS is an Array, allow this:
Where the # of elements must be no more than the size of the Array and the indices go from 0 up.
Perhaps allow this:
Where the Array originally has a size of 0, but is changed - and the actual array holding the content is reallocated - to be the number of elements in the Array Literal.
And yes - this would work in function calls, arrays embedded in records, wherever, just like existing Aggregate Literals.
What do you think?
You could (and can) use them in function calls:
Code:
void my_function( string [int] var )
{
...
}
...
my_function( { 1 : "one", 2 : "two" } );
Code:
static string [item] FAR_FUTURE_OPTION {
RIKER : "riker",
KARDASHIAN : "booze",
POINTY_EARS : "ears",
MEMORY_DISK : "memory",
EARL_GREY : "food"
};
Code:
rec1 [int,int] rmap = {4: {4: new rec1( 10, "abc" ) }, 10: {40: new rec1( 100, "xyz" ) } };
We currently can do this:
Code:
void print_agg( string name, string [int] agg )
{
print( name );
foreach key, val in agg {
print( "[ " + key + " ] -> " + val );
}
}
string [5] array1 = { 0 : "zero", 1 : "one", 2 : "two", 3 : "three", 4 : "four" };
print_agg( "array1", array1 );
string [3] array2 = { 0 : "zero", 1 : "one", 2 : "two" };
print( "" );
print_agg( "array2", array2 );
string [int] map = { 0 : "zero", 1 : "one", 2 : "two", 3 : "three", 4 : "four" };
print( "" );
print_agg( "map", map );
Code:
[color=green]> al4[/color]
array1
[ 0 ] -> zero
[ 1 ] -> one
[ 2 ] -> two
[ 3 ] -> three
[ 4 ] -> four
array2
[ 0 ] -> zero
[ 1 ] -> one
[ 2 ] -> two
map
[ 0 ] -> zero
[ 1 ] -> one
[ 2 ] -> two
[ 3 ] -> three
[ 4 ] -> four
I propose the following:
We can do this:
Code:
string [5] array1 = { 0 : "zero", 1 : "one", 2 : "two", 3 : "three", 4 : "four" };
Code:
string [5] array1 = { "zero", "one", "two", "three", "four" };
Perhaps allow this:
Code:
string [] array1 = { "zero", "one", "two", "three", "four" };
And yes - this would work in function calls, arrays embedded in records, wherever, just like existing Aggregate Literals.
What do you think?