<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 9-mar-10, at 18:56, Steven Schveighoffer wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On Tue, 09 Mar 2010 12:33:01 -0500, Andrei Alexandrescu &lt;<a href="mailto:SeeWebsiteForEmail@erdani.org">SeeWebsiteForEmail@erdani.org</a>&gt; wrote:<br><br><blockquote type="cite">In wake of printing multi-dimensional arrays, I agree that start and end delimiters should be present by default. If delimiters are present, it only makes sense to make the array look like a D array, so the ", " becomes an acceptable proposition.<br></blockquote><br>That's great!<br><br><blockquote type="cite">I'm unsure about strings - should "to" go all gung-ho on quoting and escaping quotes etc.? That's a bit odd. Consider:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">auto str = to!string("hello world");<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I'd expect the call to be an identity application that makes str equal to "hello world". So far so good. Then say I convert with "to" an array of strings to a string:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">auto str2 = to!string(["hello world"]);<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Now str2 is "\"hello world\"", i.e. has an extra pair of quotes.<br></blockquote><br>I think you mean "[\"hello world\"]"</div></blockquote><div><br></div>well the thing is again str vs repr (string, or representation), repr should output something that is basically valid D code that reproduces the same value, whereas str not, what should to! do?</div><div><br><blockquote type="cite"><div><blockquote type="cite">So "to" applied to an array does not always use "to" applied to each element of the array - it has a completely different behavior. I wonder whether that's a desirable behavior.<br></blockquote><br>I would say no. &nbsp;I guess you could make the argument that strings are already arrays treated specially, but I don't think it adds much to put the quotes there. &nbsp;Plus, it allows simpler code and documentation, you can define the conversion of an array as a purely recursive function, even if it may not be implemented that way.<br><br>Note that ranges should convert identically to arrays, making arrays special would make things odd.<br><br><blockquote type="cite">Another thing that's unclear to me is whether writeln and "to" should be defined such that<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">write(to!string(stuff))<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">and<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">writeln(stuff)<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">produce the same text. Currently that's the general plan, but I wonder whether we should change the approach.<br></blockquote></div></blockquote><div><br></div>then I find it much better to base everything on something like my&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>void writeOut(T,S...)(void delegate char[]sink, T object,S formatting)</div><div>that outputs to a sink, so that you can have output without memory allocation.</div><div><div>(well my version is little more complex because I want to accept also other stuff not just a sink <a href="http://github.com/fawzi/blip/blob/master/blip/io/BasicIO.d">http://github.com/fawzi/blip/blob/master/blip/io/BasicIO.d</a> )</div><div><br></div></div><div>If you want a single string you can easily write helpers like</div><div><span class="Apple-style-span" style="font-family: 'Bitstream Vera Sans Mono', Courier, monospace; font-size: 12px; line-height: 17px; white-space: pre; "><span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="Helvetica"><span class="Apple-style-span" style="font-size: medium; line-height: normal;">        </span></font></span>T</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">[]</span> <span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">collectAppender</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">T</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">)(</span><span class="kt" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(68, 85, 136); font-weight: bold; ">void</span> <span class="k" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">delegate</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="kt" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(68, 85, 136); font-weight: bold; ">void</span> <span class="k" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">delegate</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">T</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">[]))</span> <span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">appender</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span><span class="kt" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(68, 85, 136); font-weight: bold; ">char</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">[]</span> <span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">buf</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">=</span><span class="kc" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">null</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">)</span></span></div><div><span class="Apple-style-span" style="font-family: 'Bitstream Vera Sans Mono', Courier, monospace; font-size: 12px; line-height: 17px; white-space: pre; "><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; "></span></span>or similar ( <a href="http://github.com/fawzi/blip/blob/master/blip/container/GrowableArray.d">http://github.com/fawzi/blip/blob/master/blip/container/GrowableArray.d</a> ) that convert sink based stuff to a single string.</div><div><br></div><div>I think that that design is very efficient and clean, well I have to admit that I *hate* toString and methods that convert stuff to string, because they are unnecessarily inefficent.</div><div><br></div><div><blockquote type="cite"><div>I like that, it shows consistency. &nbsp;If you want to change the format, you can via to's parameters. &nbsp;But the most useful defaults should be the same in writeln.<br></div></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><div>Even though to is a way to get a crude serialization function, I don't know if it will be sufficient or efficient for a serious serialization library (i.e. I don't think it's worth making 'to' that smart). &nbsp;But it is sufficient as a debug tool, it just needs better defaults.<br></div></blockquote><div><br></div>as I said serialization is a different beast (at least what I want from serialization), and the "how" should be in the target serializer, the serialization function should given enough information to the serializer, so that it might serialize how it pleases to him (in particular meaningful labels should be given for serialization to json,xml,...).<br></div><div><br></div><div>Fawzi</div></body></html>