digitalmars.D.learn - Printing an std.container.Array
- Bayan Rafeh (19/19) Apr 16 2015 Executing this code:
- Daniel Kozak via Digitalmars-d-learn (3/33) Apr 16 2015 https://github.com/D-Programming-Language/phobos/pull/2875
- H. S. Teoh via Digitalmars-d-learn (9/39) Apr 16 2015 Try slicing the Array before passing it to writeln?
- Bayan Rafeh (4/44) Apr 17 2015 Thanks that works great, though I still don't understand where
- Panke (8/9) Apr 16 2015 The array contains two elements. The first equals one and the
- Daniel Kozak via Digitalmars-d-learn (4/48) Apr 16 2015 Yep, but problem is almost no one expect this, or know this. We definite...
- Panke (1/4) Apr 16 2015 How?
- Steven Schveighoffer (4/9) Apr 16 2015 By doing what is expected. Print the array contents. See my new comment
- Dennis Ritchie (13/24) Apr 16 2015 I think that this action should print the contents of the
- Steven Schveighoffer (3/27) Apr 17 2015 Yes, that's what should happen.
- Daniel =?UTF-8?B?S296w6Fr?= via Digitalmars-d-learn (4/10) Apr 16 2015 Improve doc at least. But it would be fine to have something like dump f...
Executing this code: import std.container.array; import std.stdio; int main() { writeln(Array!int([1, 2])); return 0; } outputs the following: Array!int(RefCounted!(Payload, cast(RefCountedAutoInitialize)0)(RefCountedStore(B694B0))) The strange thing is that this works fine: import std.container.array; import std.stdio; int main() { writeln(Array!int([1, 2])[0..$]); return 0; } [1, 2] How am I supposed to interpret this?
Apr 16 2015
On Thu, 16 Apr 2015 19:55:52 +0000 Bayan Rafeh via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:Executing this code: import std.container.array; import std.stdio; int main() { writeln(Array!int([1, 2])); return 0; } outputs the following: Array!int(RefCounted!(Payload, cast(RefCountedAutoInitialize)0)(RefCountedStore(B694B0))) The strange thing is that this works fine: import std.container.array; import std.stdio; int main() { writeln(Array!int([1, 2])[0..$]); return 0; } [1, 2] How am I supposed to interpret this?https://github.com/D-Programming-Language/phobos/pull/2875
Apr 16 2015
On Thu, Apr 16, 2015 at 07:55:52PM +0000, Bayan Rafeh via Digitalmars-d-learn wrote:Executing this code: import std.container.array; import std.stdio; int main() { writeln(Array!int([1, 2])); return 0; } outputs the following: Array!int(RefCounted!(Payload, cast(RefCountedAutoInitialize)0)(RefCountedStore(B694B0))) The strange thing is that this works fine: import std.container.array; import std.stdio; int main() { writeln(Array!int([1, 2])[0..$]); return 0; } [1, 2] How am I supposed to interpret this?Try slicing the Array before passing it to writeln? writeln(Array!int([1, 2])[]); Basically, there is a distinction between a container and a range that spans the items in a container. The conventional syntax for getting a range over a container's contents is the slicing operator []. T -- It said to install Windows 2000 or better, so I installed Linux instead.
Apr 16 2015
On Thursday, 16 April 2015 at 20:08:30 UTC, H. S. Teoh wrote:On Thu, Apr 16, 2015 at 07:55:52PM +0000, Bayan Rafeh via Digitalmars-d-learn wrote:Thanks that works great, though I still don't understand where the controversy is coming from. There was a mention of causing confusion between containers and ranges. How so?Executing this code: import std.container.array; import std.stdio; int main() { writeln(Array!int([1, 2])); return 0; } outputs the following: Array!int(RefCounted!(Payload, cast(RefCountedAutoInitialize)0)(RefCountedStore(B694B0))) The strange thing is that this works fine: import std.container.array; import std.stdio; int main() { writeln(Array!int([1, 2])[0..$]); return 0; } [1, 2] How am I supposed to interpret this?Try slicing the Array before passing it to writeln? writeln(Array!int([1, 2])[]); Basically, there is a distinction between a container and a range that spans the items in a container. The conventional syntax for getting a range over a container's contents is the slicing operator []. T
Apr 17 2015
On Thursday, 16 April 2015 at 19:55:53 UTC, Bayan Rafeh wrote:How am I supposed to interpret this?The array contains two elements. The first equals one and the second equals two. What happens under the hood is that Array does no provide a toString method, instead a default is used. This results in your first output. For ranges - and the slice of the array is a range while the array is not - writeln prints the elements as a special case which leads to your second output.
Apr 16 2015
On Thu, 16 Apr 2015 13:05:48 -0700 "H. S. Teoh via Digitalmars-d-learn" <digitalmars-d-learn puremagic.com> wrote:On Thu, Apr 16, 2015 at 07:55:52PM +0000, Bayan Rafeh via Digitalmars-d-learn wrote:Yep, but problem is almost no one expect this, or know this. We definitely should do better.Executing this code: import std.container.array; import std.stdio; int main() { writeln(Array!int([1, 2])); return 0; } outputs the following: Array!int(RefCounted!(Payload, cast(RefCountedAutoInitialize)0)(RefCountedStore(B694B0))) The strange thing is that this works fine: import std.container.array; import std.stdio; int main() { writeln(Array!int([1, 2])[0..$]); return 0; } [1, 2] How am I supposed to interpret this?Try slicing the Array before passing it to writeln? writeln(Array!int([1, 2])[]); Basically, there is a distinction between a container and a range that spans the items in a container. The conventional syntax for getting a range over a container's contents is the slicing operator []. T
Apr 16 2015
Yep, but problem is almost no one expect this, or know this. We definitely should do better.How?
Apr 16 2015
On 4/16/15 4:18 PM, Panke wrote:By doing what is expected. Print the array contents. See my new comment in that PR. -SteveYep, but problem is almost no one expect this, or know this. We definitely should do better.How?
Apr 16 2015
On Thursday, 16 April 2015 at 20:34:19 UTC, Steven Schveighoffer wrote:On 4/16/15 4:18 PM, Panke wrote:I think that this action should print the contents of the container, not it's type, ie [1, 2, 3, 4]: import std.stdio : writeln; import std.container.rbtree : redBlackTree; void main() { auto a = redBlackTree(1, 2, 1, 3, 4, 3); writeln(a); // std.container.rbtree.RedBlackTree!(int, "a < b", false).RedBlackTree } Will it be modified in future versions of DMD?By doing what is expected. Print the array contents. See my new comment in that PR. -SteveYep, but problem is almost no one expect this, or know this. We definitely should do better.How?
Apr 16 2015
On 4/16/15 5:18 PM, Dennis Ritchie wrote:On Thursday, 16 April 2015 at 20:34:19 UTC, Steven Schveighoffer wrote:Yes, that's what should happen. -SteveOn 4/16/15 4:18 PM, Panke wrote:I think that this action should print the contents of the container, not it's type, ie [1, 2, 3, 4]: import std.stdio : writeln; import std.container.rbtree : redBlackTree; void main() { auto a = redBlackTree(1, 2, 1, 3, 4, 3); writeln(a); // std.container.rbtree.RedBlackTree!(int, "a < b", false).RedBlackTree } Will it be modified in future versions of DMD?By doing what is expected. Print the array contents. See my new comment in that PR. -SteveYep, but problem is almost no one expect this, or know this. We definitely should do better.How?
Apr 17 2015
On Thu, 16 Apr 2015 20:18:40 +0000 Panke via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:Improve doc at least. But it would be fine to have something like dump function (equivalent of php var_dump)Yep, but problem is almost no one expect this, or know this. We definitely should do better.How?
Apr 16 2015