{"action":"closed","issue":{"url":"https://api.github.com/repos/hkuplg/fcore/issues/78","labels_url":"https://api.github.com/repos/hkuplg/fcore/issues/78/labels{/name}","comments_url":"https://api.github.com/repos/hkuplg/fcore/issues/78/comments","events_url":"https://api.github.com/repos/hkuplg/fcore/issues/78/events","html_url":"https://github.com/hkuplg/fcore/issues/78","id":59909221,"number":78,"title":"String interpolation","user":{"login":"zhiyuanshi","id":3127343,"avatar_url":"https://avatars.githubusercontent.com/u/3127343?v=3","gravatar_id":"","url":"https://api.github.com/users/zhiyuanshi","html_url":"https://github.com/zhiyuanshi","followers_url":"https://api.github.com/users/zhiyuanshi/followers","following_url":"https://api.github.com/users/zhiyuanshi/following{/other_user}","gists_url":"https://api.github.com/users/zhiyuanshi/gists{/gist_id}","starred_url":"https://api.github.com/users/zhiyuanshi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhiyuanshi/subscriptions","organizations_url":"https://api.github.com/users/zhiyuanshi/orgs","repos_url":"https://api.github.com/users/zhiyuanshi/repos","events_url":"https://api.github.com/users/zhiyuanshi/events{/privacy}","received_events_url":"https://api.github.com/users/zhiyuanshi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hkuplg/fcore/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/hkuplg/fcore/labels/minor","name":"minor","color":"f7c6c7"},{"url":"https://api.github.com/repos/hkuplg/fcore/labels/ready","name":"ready","color":"ededed"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-03-05T05:58:53Z","updated_at":"2015-03-21T13:28:14Z","closed_at":"2015-03-21T13:28:14Z","body":"## Motivation\r\n\r\nString concatenation is prevalent in a pretty printer. As the size of program grows, calling the Java `concat` method on Strings soon becomes tedious and the code is hard to read. For example,\r\n\r\n```\r\n\"before = \".concat(before.toString()).concat(\", after = \").concat(after.toString())\r\n```\r\n\r\nTherefore, I propose the support of [string interpolation] in our compiler. This can be one scheduled feature. The priority will depend on the manpower we have.\r\n\r\n[string interpolation]: http://en.wikipedia.org/wiki/String_interpolation\r\n\r\n## How it works\r\n\r\nThe same string can be written as:\r\n\r\n```\r\n\"before = \\{before}, after = \\{after}\"\r\n```\r\n\r\nAn item inserted into the string literal is wrapped inside a pair of curly parentheses, prefixed by a backslash (we call this the **\"pattern\"**). The item can be any expression. Interpolated string is then desugared into the very first snippet. String interpolation should be **type-safe** for the run time of Java programs:\r\n\r\n* if the type of the item is `String`, it stay as is;\r\n* else if the type is some Java class, the `toString` method will be implicitly called on it;\r\n* else: type error.\r\n\r\n**Note:** Interpolation is only processed inside a whole string literal. For example, the following:\r\n\r\n```\r\nlet s = \"hello\";\r\n\"\\{\".concat(\"hello\").concat(\"}\")\r\n```\r\n\r\nwon't be regarded as interpolation even though `\"\\{\".concat(\"hello\").concat(\"}\")` evaluates to `\"\\{hello}\"`, since the pattern `\"\\{...}\"` does not appear inside any whole string literals. The purpose of this restriction is to prevent the dynamic construction of *patterns* which bypasses the type checker."}}