Changeset 442, implicit Vs explicit

Michel Fortin michel.fortin at michelf.com
Tue Apr 27 11:43:46 PDT 2010


On 2010-04-27 13:55:04 -0400, bearophile <bearophileHUGS at lycos.com> said:

> Michel Fortin:
>> Ouch! I agree with the idea, but can't you find a better syntax? What
>> about this:
>> 
>> 	immutable ubyte a[256] = [1,2,3,4...]; // rest of array is padded with 4s.
>> 	immutable ubyte b[256] = [1,2,3,4]; // error: not enough values
> 
> I think this is better (note the last comma) to avoid confusion with FP values:
> immutable float a[10] = [1., 2., 3., 4., ...];

I see your point. What I suggested is that "4..." would pad the 
remaining part with 4s. If you add a comma, it looks like a separate 
value, and I'd understand the padding to be done with zero for int, nan 
for floats, in other words the default value for the type.

Another idea would be to use the AA syntax (which you can use in a 
regular array too) to specify a default value for slots where no value 
has been defined:

	immutable ubyte a[256] = [1,2,3, default: 4];
	immutable ubyte b[256] = [1,2,3,4]; // error: not enough values and no 
default value
	immutable ubyte c[256] = [40:1, 41:2, 42:3, default:4];


> Nice, and better than mine. Basically here I can accept almost any 
> syntax that is explicit :-)
> Thank you :-)

You're welcome. Let's hope it helps your case.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list