stdio line-streaming revisited
Andrei Alexandrescu (See Website For Email)
SeeWebsiteForEmail at erdani.org
Thu Mar 29 12:21:25 PDT 2007
kris wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> kris wrote:
>>
>>> 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. It's funny
>>>> this does not happen exactly because of buffering, but the program
>>>> has no control over the buffering so it should assume flushing could
>>>> happen at any time. So the correct code is:
>>>>
>>>> auto name = Cin.get;
>>>> Cout("Hello, ")(name);
>>>
>>>
>>> Well aware of that, thanks. BTW: evaluation order has been clarified
>>> before, on a similar topic.
>>
>>
>> Is that clarification identical with the one posted by Frits?
>>
>> Andreo
>
> Walter clarified, a long time ago, that D would evaluate chained-calls
> from left to right. I suggest you ask Walter?
As long as it's not in the language definition, you can't count on it. I
think this is a language defect anyhow; I am lobbying Walter to define
left-to-right order of evaluation in all cases.
Andrei
More information about the Digitalmars-d
mailing list