How should to!string handle infinite ranges?

Dave P. dave287091 at gmail.com
Tue Mar 4 21:31:57 UTC 2025


On Tuesday, 4 March 2025 at 18:13:14 UTC, monkyyy wrote:
> On Tuesday, 4 March 2025 at 10:38:24 UTC, Paul Backus wrote:
>> We're currently having a discussion about this [on Github][1]. 
>> The way I see it, there are two reasonable choices:
>>
>> 1. Return a finite string indicating that the range was 
>> infinite. For example, `"[1, 2, 3, ...]"`.
>>
>> 2. Fail to compile and print a meaningful error message using 
>> `static assert`. For example, `Can't convert an infinite range 
>> to a string`.
>>
>> As a D programmer, which behavior would you find more useful 
>> or less surprising?
>>
>> [1]: https://github.com/dlang/phobos/pull/10660
>
> `to` needs to be split up
>
> `prettyprint` should truncate *everything* to 120 chars

This is actually the correct answer. Converting something to a 
string can’t be done without knowing the intended destination. 
I’m guessing the most common use of to!string is just as a side 
effect of some debug prints and so compilation error is annoying. 
You also want the terminal output to be reasonable.


More information about the Digitalmars-d mailing list