Adding the ?. null verification

Yota via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 19 09:58:02 PDT 2014


On Wednesday, 18 June 2014 at 19:37:42 UTC, H. S. Teoh via 
Digitalmars-d wrote:
> On Wed, Jun 18, 2014 at 07:04:33PM +0000, via Digitalmars-d 
> wrote:
>> On Wednesday, 18 June 2014 at 17:56:46 UTC, Mattcoder wrote:
>> >On Wednesday, 18 June 2014 at 15:42:04 UTC, Etienne wrote:
>> >>it would be a little more practical to be able to write
>> >>
>> >>writeln(obj.member?.nested?.val);
>> >
>> >If one of these: member, nested or val == null, what will 
>> >happen with
>> >writeln()? It will print null or it will be avoided?
>> 
>> The expression needs to have exactly one type, and because all 
>> of the
>> components can be non-null, it needs to be the type of the last
>> component, in this case `val`. This means that if the one of 
>> the
>> components is null, the entire expression needs to return a 
>> value of
>> this type, presumably the `.init` value.
>> 
>> The alternative is to raise an exception (or error), but that 
>> would
>> defeat the purpose (almost, as it would be slightly better than
>> segfaulting).
>
> Here's a first stab at a library solution:
>...
> T

Won't opDispatch here destroy any hope for statement completion 
in the future?  I feel like D already has little hope for such 
tooling features, but this puts the final nail in the coffin.


More information about the Digitalmars-d mailing list