Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Range toString is ridiculous #9656

Closed
scabug opened this issue Feb 12, 2016 · 9 comments
Closed

Range toString is ridiculous #9656

scabug opened this issue Feb 12, 2016 · 9 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Feb 12, 2016

The toString on Range prints out all the elements, unless there are too many in which case it gets truncated and you can't determine what the max value is. And you have to do the math in your head if you want to know what the step is.

scala> println(1123 to 273645 by 261)
Range(1123, 1384, 1645, 1906, 2167, 2428, 2689, 2950, 3211, 3472, 3733, 3994, 4255, 4516, 4777, 5038, 5299, 5560, 5821, 6082, 6343, 6604, 6865, 7126, 7387, 7648, 7909, 8170, 8431, 8692, 8953, 9214, 9475, 9736, 9997, 10258, 10519, 10780, 11041, 11302, 11563, 11824, 12085, 12346, 12607, 12868, 13129, 13390, 13651, 13912, 14173, 14434, 14695, 14956, 15217, 15478, 15739, 16000, 16261, 16522, 16783, 17044, 17305, 17566, 17827, 18088, 18349, 18610, 18871, 19132, 19393, 19654, 19915, 20176, 20437, 20698, 20959, 21220, 21481, 21742, 22003, 22264, 22525, 22786, 23047, 23308, 23569, 23830, 24091, 24352, 24613, 24874, 25135, 25396, 25657, 25918, 26179, 26440, 26701, 26962, 27223, 27484, 27745, 28006, 28267, 28528, 28789, 29050, 29311, 29572, 29833, 30094, 30355, 30616, 30877, 31138, 31399, 31660, 31921, 32182, 32443, 32704, 32965, 33226, 33487, 33748, 34009, 34270, 34531, 34792, 35053, 35314, 35575, 35836, 36097, 36358, 36619, 36880, 37141, 37402, 37663, 37924, 38185, 38446, 38707, 38968, 39229, 39490, 39751, 40012, 40273, 40534, 40795, 41056, 41317, 41578, 41839, 42100, 42361, 42622, 42883, 43144, 43405, 43666, 43927, 44188, 44449, 44710, 44971, 45232, 45493, 45754, 46015, 46276, 46537, 46798, 47059, 47320, 47581, 47842, 48103, 48364, 48625, 48886, 49147, 49408, 49669, 49930, 50191, 50452, 50713, 50974, 51235, 51496, 51757, 52018, 52279, 52540, 52801, 53062, 53323, 53584, 53845, 54106, 54367, 54628, 54889, 55150, 55411, 55672, 55933, 56194, 56455, 56716, 56977, 57238, 57499, 57760, 58021, 58282, 58543, 58804, 59065, 59326, 59587, 59848, 60109, 60370, 60631, 60892, 61153, 61414, 61675, 61936, 62197, 62458, 62719, 62980, 63241, 63502, 63763, 64024, 64285, 64546, 64807, 65068, 65329, 65590, 65851, 66112, 66373, 66634, 66895, 67156, 67417, 67678, 67939, 68200, 68461, 68722, 68983, 69244, 69505, 69766, 70027, 70288, 70549, 70810, 71071, 71332, 71593, 71854, 72115, 72376, 72637, 72898, 73159, 73420, 73681, 73942, 74203, 74464, 74725, 74986, 75247, 75508, 75769, 76030, 76291, 76552, 76813, 77074, 77335, 77596, 77857, 78118, 78379, 78640, 78901, 79162, 79423, 79684, 79945, 80206, 80467, 80728, 80989, 81250, 81511, 81772, 82033, 82294, 82555, 82816, 83077, 83338, 83599, 83860, 84121, 84382, 84643, 84904, 85165, 85426, 85687, 85948, 86209, 86470, 86731, 86992, 87253, 87514, 87775, 88036, 88297, 88558, 88819, 89080, 89341, 89602, 89863, 90124, 90385, 90646, 90907, 91168, 91429, 91690, 91951, 92212, 92473, 92734, 92995, 93256, 93517, 93778, 94039, 94300, 94561, 94822, 95083, 95344, 95605, 95866, 96127, 96388, 96649, 96910, 97171, 97432, 97693, 97954, 98215, 98476, 98737, 98998, 99259, 99520, 99781, 100042, 100303, 100564, 100825, 101086, 101347, 101608, 101869, 102130, 102391, 102652, 102913, 103174, 103435, 103696, 103957, 104218, 104479, 104740, 105001, 105262, 105523, 105784, 106045, 106306, 106567, 106828, 107089, 107350, 107611, 107872, 108133, 108394, 108655, 108916, 109177, 109438, 109699, 109960, 110221, 110482, 110743, 111004, 111265, 111526, 111787, 112048, 112309, 112570, 112831, 113092, 113353, 113614, 113875, 114136, 114397, 114658, 114919, 115180, 115441, 115702, 115963, 116224, 116485, 116746, 117007, 117268, 117529, 117790, 118051, 118312, 118573, 118834, 119095, 119356, 119617, 119878, 120139, 120400, 120661, 120922, 121183, 121444, 121705, 121966, 122227, 122488, 122749, 123010, 123271, 123532, 123793, 124054, 124315, 124576, 124837, 125098, 125359, 125620, 125881, 126142, 126403, 126664, 126925, 127186, 127447, 127708, 127969, 128230, 128491, 128752, 129013, 129274, 129535, 129796, 130057, 130318, 130579, 130840, 131101, 131362, 131623, 131884, 132145, 132406, 132667, 132928, 133189, 133450, 133711, 133972, 134233, 134494, ... )

I suggest that something like Range(start, stop, step) might be more useful.

@scabug
Copy link
Author

scabug commented Feb 12, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9656?orig=1
Reporter: Rob Norris (rnorris)

@scabug
Copy link
Author

scabug commented Feb 12, 2016

Rob Norris (rnorris) said:
Also ridiculous: JIRA. No idea how to make my example show up in monospace.

@scabug
Copy link
Author

scabug commented Feb 13, 2016

@som-snytt said:
The scaladoc is also funky.

It's not like the max value for printing is some arbitrary value.

private[immutable] val MAX_PRINT = 512  // some arbitrary value

The question is why does it use JAVA_CONVENTIONS.

You don't get any help from stringOf, where you can specify max, because

    // When doing our own iteration is dangerous
    def useOwnToString(x: Any) = x match {
      // Range/NumericRange have a custom toString to avoid walking a gazillion elements
      case _: Range | _: NumericRange[_] => true

The irony is that the REPL thinks a million elements is also too much, and inserts its own ellipsis.

scala> 1123 to 273645 by 261
res1: scala.collection.immutable.Range = Range(1123, 1384, [snip] 29833, 30094, 3...

If only there were a type class for this sort of thing... Call it the TrailingEllipsis type class...

@scabug
Copy link
Author

scabug commented Feb 28, 2016

Stephen Robinson-Burns (stevorobs3) said:
I have added a pull request here .

@scabug
Copy link
Author

scabug commented Feb 28, 2016

@som-snytt said:
Or maybe here: scala/scala#5001

@scabug
Copy link
Author

scabug commented Feb 28, 2016

@SethTisue said:
5001: A Range Odyssey

@scabug
Copy link
Author

scabug commented Mar 1, 2016

Stephen Robinson-Burns (stevorobs3) said:
Yes - thanks that's the right link. The branch is now building and has passed all the tests - not sure what the next stage is for getting it into a release

@scabug
Copy link
Author

scabug commented Mar 2, 2016

@som-snytt said:
I think this issue is blocked until the Scala team is Home on the Range again. Really, the ticket is at least two or three puns away from consideration.

@scabug
Copy link
Author

scabug commented May 24, 2016

@szeiger said:
Fixed in scala/scala#5175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants