{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/249","repository_url":"https://api.github.com/repos/dotnet/csharplang","labels_url":"https://api.github.com/repos/dotnet/csharplang/issues/249/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/csharplang/issues/249/comments","events_url":"https://api.github.com/repos/dotnet/csharplang/issues/249/events","html_url":"https://github.com/dotnet/csharplang/issues/249","id":213452298,"number":249,"title":"Returnable block or Anonymous immediate local function","user":{"login":"Thaina","id":1042507,"avatar_url":"https://avatars2.githubusercontent.com/u/1042507?v=3","gravatar_id":"","url":"https://api.github.com/users/Thaina","html_url":"https://github.com/Thaina","followers_url":"https://api.github.com/users/Thaina/followers","following_url":"https://api.github.com/users/Thaina/following{/other_user}","gists_url":"https://api.github.com/users/Thaina/gists{/gist_id}","starred_url":"https://api.github.com/users/Thaina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Thaina/subscriptions","organizations_url":"https://api.github.com/users/Thaina/orgs","repos_url":"https://api.github.com/users/Thaina/repos","events_url":"https://api.github.com/users/Thaina/events{/privacy}","received_events_url":"https://api.github.com/users/Thaina/received_events","type":"User","site_admin":false},"labels":[{"id":537024200,"url":"https://api.github.com/repos/dotnet/csharplang/labels/Discussion","name":"Discussion","color":"c2e0c6","default":false},{"id":545773793,"url":"https://api.github.com/repos/dotnet/csharplang/labels/Feature%20Request","name":"Feature Request","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":20,"created_at":"2017-03-10T21:06:56Z","updated_at":"2017-03-12T01:36:16Z","closed_at":null,"body":"I have seen some proposal (include mine) wanting to have a value set from block syntax\r\n\r\nAnd the approach mostly suggest that we should modified some syntax into one-line-able syntax\r\n`inline try` #220 for example\r\n\r\nWhich I have seen it more and more complicate to fit everything in one line\r\nSo I want to propose alternative. We should have some syntax that could make a block to imitate function. The block that make a scope variable not leaked out. Can return value(s) and do complicate task like local function. But immediately execute like a code there\r\n\r\nI don't know what operator we could use, please bear with my `=:` for now\r\n\r\n```C#\r\nvar text = \"42\";\r\nvar x =: {           // Just notice its little cute somehow\r\n    try { return int.Parse(text); }\r\n    catch(Exception e) { return -1; }\r\n};\r\n\r\nvar y =: {\r\n    var httpResponse = await HttpParser(text).GetResponseAsync();\r\n    using(var stream = httpResponse.GetResponseStream())\r\n         return int.Parse(stream.ReadToEnd());\r\n};\r\n\r\nvar z =: {\r\n    if(condition0)\r\n        return 0;\r\n\r\n    DoSomething();\r\n    if(condition1)\r\n        return 1;\r\n\r\n    DoSomeOtherthing();\r\n    return -1;\r\n};\r\n```\r\n\r\nThis block syntax work like normal `{}` scope. It can access outside variable but variable declared in that block would not leaked. And can use `return` to return value from the block to variable outside\r\n\r\nIt should also be able to return void to just do a logic that could be cut short\r\n\r\n```C#\r\n=: {    //now this block is like void function\r\n    if(condition0)\r\n        return;\r\n\r\n    DoSomething();\r\n    if(condition1)\r\n        return;\r\n\r\n    DoSomeOtherthing();\r\n};\r\n```\r\n\r\nAnd I wish we could yield\r\n\r\n```C#\r\nIEnumerable<int> numbers =: {\r\n    yield return 0;\r\n    yield return 1;\r\n    if(condition0)\r\n        yield break;\r\n\r\n    yield return 2;\r\n};\r\n\r\nvar oddNumberArray =: {\r\n    yield return 0;\r\n    yield return 1;\r\n    if(condition0)\r\n        yield break;\r\n\r\n    yield return 2;\r\n    yield return 3;\r\n}.Where((n) => n % 2 == 1).ToArray();\r\n```"},"comment":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/comments/285914509","html_url":"https://github.com/dotnet/csharplang/issues/249#issuecomment-285914509","issue_url":"https://api.github.com/repos/dotnet/csharplang/issues/249","id":285914509,"user":{"login":"eyalsk","id":3756641,"avatar_url":"https://avatars0.githubusercontent.com/u/3756641?v=3","gravatar_id":"","url":"https://api.github.com/users/eyalsk","html_url":"https://github.com/eyalsk","followers_url":"https://api.github.com/users/eyalsk/followers","following_url":"https://api.github.com/users/eyalsk/following{/other_user}","gists_url":"https://api.github.com/users/eyalsk/gists{/gist_id}","starred_url":"https://api.github.com/users/eyalsk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eyalsk/subscriptions","organizations_url":"https://api.github.com/users/eyalsk/orgs","repos_url":"https://api.github.com/users/eyalsk/repos","events_url":"https://api.github.com/users/eyalsk/events{/privacy}","received_events_url":"https://api.github.com/users/eyalsk/received_events","type":"User","site_admin":false},"created_at":"2017-03-12T01:36:16Z","updated_at":"2017-03-12T01:36:16Z","body":"@gafter Well, yes but then you need to define it and then execute it whereas here I guess it offers a syntax that does both in \"one go\"."}}
{"actor":{"display_login":"eyalsk"}}