stdio line-streaming revisited

kris foo at bar.com
Thu Mar 29 12:13:02 PDT 2007


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?



More information about the Digitalmars-d mailing list