Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
February 14, 2014 [Issue 12162] New: writeln(args) and writefln("%s", args) have different semantics with variadic args | ||||
---|---|---|---|---|
| ||||
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 --- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2014-02-14 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: ------- |
February 14, 2014 [Issue 12162] writeln(args) and writefln("%s", args) have different semantics with variadic args | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | https://d.puremagic.com/issues/show_bug.cgi?id=12162 Jakob Ovrum <jakobovrum@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakobovrum@gmail.com --- Comment #1 from Jakob Ovrum <jakobovrum@gmail.com> 2014-02-14 12:44:48 PST --- (In reply to comment #0) > ----- > 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: ------- |
February 14, 2014 [Issue 12162] writeln(args) and writefln("%s", args) have different semantics with variadic args | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | https://d.puremagic.com/issues/show_bug.cgi?id=12162 --- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2014-02-14 12:47:18 PST --- (In reply to comment #1) > 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: ------- |
February 14, 2014 [Issue 12162] writeln(args) and writefln("%s", args) have different semantics with variadic args | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | https://d.puremagic.com/issues/show_bug.cgi?id=12162 --- Comment #3 from Jakob Ovrum <jakobovrum@gmail.com> 2014-02-14 12:49:06 PST --- (In reply to comment #2) > (In reply to comment #1) > > 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: ------- |
February 14, 2014 [Issue 12162] writeln(args) and writefln("%s", args) have different semantics with variadic args | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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 --- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2014-02-14 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: ------- |
February 14, 2014 [Issue 12162] writeln(args) and writefln("%s", args) have different semantics with variadic args | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | https://d.puremagic.com/issues/show_bug.cgi?id=12162 --- Comment #5 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2014-02-14 12:53:09 PST --- (In reply to comment #4) > 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: ------- |
February 14, 2014 [Issue 12162] writeln(args) and writefln("%s", args) have different semantics with variadic args | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | https://d.puremagic.com/issues/show_bug.cgi?id=12162 --- Comment #6 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2014-02-14 12:55:28 PST --- (In reply to comment #5) > (In reply to comment #4) > > 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: ------- |
February 14, 2014 [Issue 12162] writeln(args) and writefln("%s", args) have different semantics with variadic args | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | https://d.puremagic.com/issues/show_bug.cgi?id=12162 --- Comment #7 from Jakob Ovrum <jakobovrum@gmail.com> 2014-02-14 12:58:29 PST --- (In reply to comment #6) > (In reply to comment #5) > > (In reply to comment #4) > > > 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: ------- |
Copyright © 1999-2021 by the D Language Foundation