stdio line-streaming revisited
Sean Kelly
sean at f4.ca
Thu Mar 29 10:13:31 PDT 2007
Andrei Alexandrescu (See Website For Email) wrote:
> kris wrote:
>> Sean Kelly wrote:
>> [snip]
>>> I must be missing something. Why is the following not acceptable?
>>>
>>> import tango.io.Console;
>>>
>>> void main()
>>> {
>>> char[] name;
>>> Cout( "Please enter your name: " ).flush;
>>> Cin.nextLine( name );
>>> Cout( "Hello, " )( name )( "!" );
>>> }
>>
>>
>> There used to be a tango/example like this variation:
>>
>> import tango.io.Console;
>>
>> void main()
>> {
>> Cout ("Please enter your name: ").flush;
>> Cout ("Hello, ") (Cin.get);
>> }
>
> Ah, also, the last line is translated into:
>
> Cout.opCall("Hello, ").opCall(Cin.get);
>
> D does not specify evaluation order, so the code might end up printing
> "Hello, " before reading the standard input.
We discussed this a long time ago and came to the conclusion that while
the D spec does not guarantee evaluation order for this scenario, it
seems impossible for it to be anything other than left to right because
the chained calls rely on the return value from previous calls. If this
is untrue then I'd love to know the reasoning. Perhaps an aggressive
inlining mechanism could violate this?
Sean
More information about the Digitalmars-d
mailing list