Bug 5376 – writeln doesn't print immutable lazy sequences

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-12-26T02:05:00Z
Last change time
2015-12-09T12:49:18Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-12-26T02:05:18Z
import std.stdio, std.algorithm; void main() { const(int[]) arr1 = [1, 2, 3]; auto sequence1 = map!q{ -a }(arr1); writeln(sequence1); const sequence2 = map!q{ -a }(arr1); writeln(sequence2); immutable(int[]) arr2 = [1, 2, 3]; immutable sequence3 = map!q{ -a }(arr2); writeln(sequence3); } DMD 2.051 prints: [-1, -2, -3] const(Map!(result,const(int[]))) immutable(Map!(result,immutable(int[]))) But I'd like it to print the contents of the second and third lazy sequences too, like (note the semicolons, very useful to tell apart arrays from lazy sequences, see bug 3813 for the rationale): [-1; -2; -3] [-1; -2; -3] [-1; -2; -3] Or maybe something like: [-1; -2; -3] const([-1; -2; -3]) immutable([-1; -2; -3]) But note that this is currently a syntax error: void main() { auto a = const([1, 2, 3]); }
Comment #1 by simen.kjaras — 2010-12-26T04:05:14Z
This is the same old problem of ranges not supporting tail-const or tail-immutable. I've filed that as a separate issue - http://d.puremagic.com/issues/show_bug.cgi?id=5377
Comment #2 by lt.infiltrator — 2015-12-09T10:43:27Z
2.069 prints the types and contents of the sequences: ============ [-1, -2, -3] const(MapResult!(unaryFun, const(int)[]))([1, 2, 3]) immutable(MapResult!(unaryFun, immutable(int)[]))([1, 2, 3]) ============ Is this acceptable?
Comment #3 by bearophile_hugs — 2015-12-09T12:49:18Z
(In reply to Infiltrator from comment #2) > 2.069 prints the types and contents of the sequences: > ============ > [-1, -2, -3] > const(MapResult!(unaryFun, const(int)[]))([1, 2, 3]) > immutable(MapResult!(unaryFun, immutable(int)[]))([1, 2, 3]) > ============ > > Is this acceptable? Yes, closed.