www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12162] New: writeln(args) and writefln("%s", args) have different semantics with variadic args

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12162

           Summary: writeln(args) and writefln("%s", args) have different
                    semantics with variadic args
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



12:38:46 PST ---
-----
import std.stdio;

void test(T...)(T args)
{
    writefln("%s", args);
    writeln(args);
}

void main()
{
    test(1, 2, 3, 4);
}
-----

$ dmd test.d
 1
 1234
-- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 14 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12162


Jakob Ovrum <jakobovrum gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakobovrum gmail.com



---

 -----
 import std.stdio;
 
 void test(T...)(T args)
 {
     writefln("%s", args);
     writeln(args);
 }
 
 void main()
 {
     test(1, 2, 3, 4);
 }
 -----
 
 $ dmd test.d
 1
 1234
Well, what did you expect? I personally would've expected it to error on the basis of having received too many arguments (or was that error phased out?), but this behaviour looks correct to me. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 14 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12162




12:47:18 PST ---

 Well, what did you expect?
I guess I'm looking for some kind of eager version of %s? This isn't necessarily a bug, but could be an enhancement request (unless it can already be done with another format spec?). -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 14 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12162




---


 Well, what did you expect?
I guess I'm looking for some kind of eager version of %s? This isn't necessarily a bug, but could be an enhancement request (unless it can already be done with another format spec?).
It would necessitate treating all trailing arguments equally (which would arguably only make sense for %s). -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 14 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12162


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



12:52:14 PST ---
Ah I know of a cute trick though:

writefln("%s", args.only);

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 14 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12162




12:53:09 PST ---

 Ah I know of a cute trick though:
 
 writefln("%s", args.only);
And come to think of it, I think bearophile has a couple of format() enhancement requests specifically for tuples. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 14 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12162




12:55:28 PST ---


 Ah I know of a cute trick though:
 
 writefln("%s", args.only);
And come to think of it, I think bearophile has a couple of format() enhancement requests specifically for tuples.
Specifically, the following works for arrays but not for tuples: writefln("%(%s %)", [1, 2]); // prints "1 2" Perhaps if we could modify the syntax a little bit.. writefln("%!(%s %)", TypeTuple!(1, 2)); // would print "1 2" Disregard the TypeTuple misnomer though. :) -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 14 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12162




---



 Ah I know of a cute trick though:
 
 writefln("%s", args.only);
And come to think of it, I think bearophile has a couple of format() enhancement requests specifically for tuples.
Specifically, the following works for arrays but not for tuples: writefln("%(%s %)", [1, 2]); // prints "1 2" Perhaps if we could modify the syntax a little bit.. writefln("%!(%s %)", TypeTuple!(1, 2)); // would print "1 2" Disregard the TypeTuple misnomer though. :)
It is no surprise that tuples (aka template argument list) work differently from arrays, considering their auto-expansive behaviour. bearophile's ER pertains std.typecons.Tuple, not in-built "type tuples". -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 14 2014