Re: Printing an std.container.Array
On Thu, 16 Apr 2015 20:18:40 + Panke via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Yep, but problem is almost no one expect this, or know this. We definitely should do better. How? Improve doc at least. But it would be fine to have something like dump function (equivalent of php var_dump)
Re: Printing an std.container.Array
On 4/16/15 5:18 PM, Dennis Ritchie wrote: On Thursday, 16 April 2015 at 20:34:19 UTC, Steven Schveighoffer wrote: On 4/16/15 4:18 PM, Panke wrote: Yep, but problem is almost no one expect this, or know this. We definitely should do better. How? By doing what is expected. Print the array contents. See my new comment in that PR. -Steve 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? Yes, that's what should happen. -Steve
Re: Printing an std.container.Array
On Thursday, 16 April 2015 at 20:08:30 UTC, H. S. Teoh wrote: On Thu, Apr 16, 2015 at 07:55:52PM +, 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 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?
Re: Printing an std.container.Array
On Thursday, 16 April 2015 at 20:34:19 UTC, Steven Schveighoffer wrote: On 4/16/15 4:18 PM, Panke wrote: Yep, but problem is almost no one expect this, or know this. We definitely should do better. How? By doing what is expected. Print the array contents. See my new comment in that PR. -Steve 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?
Re: Printing an std.container.Array
On Thu, 16 Apr 2015 19:55:52 + 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
Re: Printing an std.container.Array
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 +, 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 Yep, but problem is almost no one expect this, or know this. We definitely should do better.
Re: Printing an std.container.Array
On Thu, Apr 16, 2015 at 07:55:52PM +, 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.
Printing an std.container.Array
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?
Re: Printing an std.container.Array
On 4/16/15 4:18 PM, Panke wrote: Yep, but problem is almost no one expect this, or know this. We definitely should do better. How? By doing what is expected. Print the array contents. See my new comment in that PR. -Steve
Re: Printing an std.container.Array
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.
Re: Printing an std.container.Array
Yep, but problem is almost no one expect this, or know this. We definitely should do better. How?