Few things II
Bill Baxter
dnewsgroup at billbaxter.com
Tue Aug 7 19:22:15 PDT 2007
Oskar Linde wrote:
> bearophile wrote:
>> 2d) Regarding the printing I think it's not nice that:
>> writefln(["1", "2"])
>> prints the same thing as:
>> writefln([1, 2])
>> So maybe writefln can use "" when printing strings inside arrays/AAs,
>> to differentiate them.
>
> In that case, writefln(1) should not print the same thing as
> writefln("1") either. But I agree that it would be useful to have a
> function that prints strings with "". Preferably, it should be able to
> convert any expression of basic types into a string representation, that
> when parsed by the compiler as a literal yields an identical value.
>
This is the heart of the repr/str distinction from Python that was
mentioned. In Python instead of just one toString method, you have
__str__ and __repr__.
__str__ is supposed to return a version that looks nice for "human reading"
__repr__ is supposed to return a string that (if possible) would
recreate the object if passed to the interpreter.
So the str of "1" prints without quote characters, but repr of "1"
prints with quotes.
--bb
More information about the Digitalmars-d
mailing list