stdio line-streaming revisited

James Dennett jdennett at acm.org
Thu Mar 29 21:55:46 PDT 2007


Sean Kelly 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.
> 
> 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. 

All you get from that is a partial order that says
that the arguments to a function must be evaluated
before that function is called.  There's nothing
to say which order they're evaluated in; Cin.get
can be called at any time before the opCall that
uses its result, including being the first call in
the statement.  There's no requirement for anything
to happen before Cin.get is called.

-- James



More information about the Digitalmars-d mailing list