[Issue 3813] Bad writeln of arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Sep 5 02:53:38 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=3813



--- Comment #17 from bearophile_hugs at eml.cc 2011-09-05 02:53:08 PDT ---
(In reply to comment #16)
> Let's use [,,,] for all ranges. Thanks Kenji for your work.

What's your rationale for this decision?

---------------------------

In 2.055beta the printing situation is improved a lot, thanks to your work. I
see two things where I'd like further improvement:

This code:

import std.stdio;
void main() {
    int[2] array1 = [1, 2];
    writeln(array1);
    double[2] array2 = [1.0, 2.0];
    writeln(array2);
}


With DMD 2.055beta prints:
[1, 2]
[1, 2]

This is not good, because from the text you can't tell FP point numbers from
integer ones. In a similar situation Python prints this, that I think is a
better output:

[1.0, 2.0]
[1.0, 2.0]

------------------------------

This code:

import std.stdio, std.typecons;
void main () {
    writeln(tuple(1, "xx"));
}


Prints:
Tuple!(int,string)(1, xx)


But I'd like:
tuple(1, "xx")


That's closer to array representation, because D tuples are not TypeTuples,
they have a different semantics (with a TypeTuple is probably better to not
print the "" around strings).

Python does something similar (Python uses ' insted if " but this is not
relevant):

>>> (1, "xx")
(1, 'xx')

--------------------------

This is a less important thing. This code:


import std.stdio;
void main () {
    writeln([1:2, 3:4]);
}


Prints:
[1:2, 3:4]


While Python 2.6 prints:

>>> {1:2, 3:4}
{1: 2, 3: 4}

Python adds a space after the colon probably to increase readability.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list