www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21860] New: readln return value in the EOF case

https://issues.dlang.org/show_bug.cgi?id=21860

          Issue ID: 21860
           Summary: readln return value in the EOF case
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: kdevel vogtner.de

https://dlang.org/phobos/std_stdio.html#.File.readln does not define what the
function returns in case of EOF. Only the code example

   // Reads `stdin` and writes it to `stdout`.
   import std.stdio;

   void main()
   {
       string line;
       while ((line = stdin.readln()) !is null)
           write(line);
   }

suggests that a special string is returned which "is" null in that case.
Some design have been discussed back and forth [1]. But it seems that
the actual sentinel value is not null [2] but "" (the empty string).
Can this be made explicit both in the section "Return value" and in the
example?

[1]
<http://forum.dlang.org/post/mailman.2323.1382117110.1719.digitalmars-d puremagic.com>
    Re: Empty VS null array?

[2] This null value is not defined anywhere where it should be:
    <https://dlang.org/spec/arrays.html>

--
Apr 25 2021