{"action":"opened","issue":{"url":"https://api.github.com/repos/crystal-jp/issues/issues/11","labels_url":"https://api.github.com/repos/crystal-jp/issues/issues/11/labels{/name}","comments_url":"https://api.github.com/repos/crystal-jp/issues/issues/11/comments","events_url":"https://api.github.com/repos/crystal-jp/issues/issues/11/events","html_url":"https://github.com/crystal-jp/issues/issues/11","id":105110615,"number":11,"title":"文字列のRangeの仕様について","user":{"login":"kubo39","id":927749,"avatar_url":"https://avatars.githubusercontent.com/u/927749?v=3","gravatar_id":"","url":"https://api.github.com/users/kubo39","html_url":"https://github.com/kubo39","followers_url":"https://api.github.com/users/kubo39/followers","following_url":"https://api.github.com/users/kubo39/following{/other_user}","gists_url":"https://api.github.com/users/kubo39/gists{/gist_id}","starred_url":"https://api.github.com/users/kubo39/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kubo39/subscriptions","organizations_url":"https://api.github.com/users/kubo39/orgs","repos_url":"https://api.github.com/users/kubo39/repos","events_url":"https://api.github.com/users/kubo39/events{/privacy}","received_events_url":"https://api.github.com/users/kubo39/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-09-06T18:54:25Z","updated_at":"2015-09-06T18:54:25Z","closed_at":null,"body":"現時点、以下のバージョンにおける文字列のRangeの仕様です。\r\n\r\n```\r\n$ crystal -v\r\nCrystal 0.7.7 [170f859] (Sat Sep  5 02:53:51 UTC 2015)\r\n```\r\n\r\n現在 `\"A\"..\"z\"` は \"A\" から始まり \"...z\" で終わるような文字列集合を表します。\r\n\r\n```crystal\r\np (\"A\"..\"z\").take(27).to_a #=> [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \"M\", \"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\", \"Z\", \"AA\"]\r\n```\r\n\r\nこれがどういうことかというと、以下のようなコードを書くとプログラムが停止しなくなります。(実際はOutOfMemoryになるでしょう)\r\n\r\n```crystal\r\n (\"A\"..\"z\").to_a\r\n```\r\n\r\nRubyでは以下のような仕様になっています。これはRuby内部では `String#succ` を単純にたたいてるだけではなくて `\"Z\".ord.succ.chr` のようになっているためです。\r\n\r\n```\r\n$ ruby -v\r\nruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]\r\n $ irb\r\nirb(main):001:0> (\"A\"..\"z\").to_a\r\n=> [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \"M\", \"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\", \"Z\", \"[\", \"\\\\\", \"]\", \"^\", \"_\", \"`\", \"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\", \"n\", \"o\", \"p\", \"q\", \"r\", \"s\", \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\"]\r\n```\r\n\r\n* Crystalの仕様は妥当か？\r\n* Rubyの仕様に合わせるべきか？\r\n* そうでないならどのような仕様にするべきか？\r\n\r\nこのあたりを念頭に議論したいと思っています。"}}