{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/198","repository_url":"https://api.github.com/repos/dotnet/csharplang","labels_url":"https://api.github.com/repos/dotnet/csharplang/issues/198/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/csharplang/issues/198/comments","events_url":"https://api.github.com/repos/dotnet/csharplang/issues/198/events","html_url":"https://github.com/dotnet/csharplang/issues/198","id":210524946,"number":198,"title":"Discussion: Range operator","user":{"login":"HaloFour","id":10102290,"avatar_url":"https://avatars.githubusercontent.com/u/10102290?v=3","gravatar_id":"","url":"https://api.github.com/users/HaloFour","html_url":"https://github.com/HaloFour","followers_url":"https://api.github.com/users/HaloFour/followers","following_url":"https://api.github.com/users/HaloFour/following{/other_user}","gists_url":"https://api.github.com/users/HaloFour/gists{/gist_id}","starred_url":"https://api.github.com/users/HaloFour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HaloFour/subscriptions","organizations_url":"https://api.github.com/users/HaloFour/orgs","repos_url":"https://api.github.com/users/HaloFour/repos","events_url":"https://api.github.com/users/HaloFour/events{/privacy}","received_events_url":"https://api.github.com/users/HaloFour/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-02-27T15:55:50Z","updated_at":"2017-02-27T16:53:21Z","closed_at":null,"body":"### Summary\r\n\r\nI propose a general purpose range operator which can be used to obtain a range a integral values.  This range can then be used in loops, patterns or slices:\r\n\r\n```cs\r\nvar slice = source[5..10];\r\nfor (var i in 5..10) {\r\n    Console.WriteLine(i);\r\n}\r\n```\r\n\r\n### Questions\r\n\r\n1. Can a range expression be assigned directly to a variable?  If so, what is the type of that expression?\r\n    ```cs\r\n    var range = 5..10;  // int[]?  IEnumerable<int>?  IReadOnlyList<int>?  Range<int>?  None of the above?\r\n    ```\r\n1. What exact syntax should be supported?  There are numerous examples found in other languages.\r\n    ```cs\r\n    var perl = source[5..10];\r\n    var swift = source[5...10];\r\n    var basic = source[5 to 10];\r\n    var python = source[5:10];\r\n    ```\r\n1. Should the upper boundary be inclusive or exclusive?  Should the syntax of the operator support explicit inclusivity?\r\n    ```cs\r\n    var range1 = 5...10;  // 5, 6, 7, 8, 9, 10\r\n    var swift = 5..<10;  // 5, 6, 7, 8, 9\r\n    var perl = 5^..10; // 6, 7, 8, 9, 10\r\n    ```\r\n1. Should the syntax include the ability to specify a step or a stride?\r\n    ```cs\r\n    var stride = 5:10:2; // 5, 7, 9\r\n    ```\r\n1. Should the syntax include specifying a range relative to an anchor, such as the end of an array/collection?\r\n    ```cs\r\n    var source = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };\r\n    var slice1 = source[-3:-1]; // { 8, 9, 10 }\r\n    ```\r\n1. Should the range syntax be supported in pattern matching against integral (or comparable) types?\r\n    ```cs\r\n    int value = CalculateSomeValue();\r\n    if (value is 10..50) {\r\n        Console.WriteLine(\"The value is somewhere between 10 and 50!\");\r\n    }\r\n    Point p = CalculateSomePoint();\r\n    switch (p) {\r\n        case (x, -25:-25):\r\n            Console.WriteLine(\"The point is near the central axis!\");\r\n            break;\r\n    }\r\n    ```"},"comment":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/comments/282778924","html_url":"https://github.com/dotnet/csharplang/issues/198#issuecomment-282778924","issue_url":"https://api.github.com/repos/dotnet/csharplang/issues/198","id":282778924,"user":{"login":"orthoxerox","id":8640149,"avatar_url":"https://avatars.githubusercontent.com/u/8640149?v=3","gravatar_id":"","url":"https://api.github.com/users/orthoxerox","html_url":"https://github.com/orthoxerox","followers_url":"https://api.github.com/users/orthoxerox/followers","following_url":"https://api.github.com/users/orthoxerox/following{/other_user}","gists_url":"https://api.github.com/users/orthoxerox/gists{/gist_id}","starred_url":"https://api.github.com/users/orthoxerox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orthoxerox/subscriptions","organizations_url":"https://api.github.com/users/orthoxerox/orgs","repos_url":"https://api.github.com/users/orthoxerox/repos","events_url":"https://api.github.com/users/orthoxerox/events{/privacy}","received_events_url":"https://api.github.com/users/orthoxerox/received_events","type":"User","site_admin":false},"created_at":"2017-02-27T16:53:21Z","updated_at":"2017-02-27T16:53:21Z","body":"In my opinion:\r\n\r\n1. Can a range expression be assigned directly to a variable? If so, what is the type of that expression? \r\nYes, `Range<T> : IEnumerable<T>`\r\n\r\n2. What exact syntax should be supported? There are numerous examples found in other languages.\r\n`e1..e2`\r\n\r\n3. Should the upper boundary be inclusive or exclusive? Should the syntax of the operator support explicit inclusivity? \r\nInclusive. `..<` can be the exclusive operator.\r\n\r\n4. Should the syntax include the ability to specify a step or a stride?\r\nNo.\r\n\r\n5. Should the syntax include specifying a range relative to an anchor, such as the end of an array/collection?\r\nYes, if negative indexing is added in general.\r\n\r\n6. Should the range syntax be supported in pattern matching against integral (or comparable) types?\r\nYes.\r\n\r\nAnd my own suggestion: range operator should be applicable to all types that support `IComparable<T>` (or `SComparable<T>`) and `++`/`--` operators (`SSuccessive<T>`?)."}}
{"actor":{"display_login":"orthoxerox"}}