{"action":"created","issue":{"url":"https://api.github.com/repos/probmods/webppl/issues/61","labels_url":"https://api.github.com/repos/probmods/webppl/issues/61/labels{/name}","comments_url":"https://api.github.com/repos/probmods/webppl/issues/61/comments","events_url":"https://api.github.com/repos/probmods/webppl/issues/61/events","html_url":"https://github.com/probmods/webppl/issues/61","id":63282153,"number":61,"title":"CPS breaks function order independence in the presence of function wrappers/decorators","user":{"login":"dritchie","id":2229830,"avatar_url":"https://avatars.githubusercontent.com/u/2229830?v=3","gravatar_id":"","url":"https://api.github.com/users/dritchie","html_url":"https://github.com/dritchie","followers_url":"https://api.github.com/users/dritchie/followers","following_url":"https://api.github.com/users/dritchie/following{/other_user}","gists_url":"https://api.github.com/users/dritchie/gists{/gist_id}","starred_url":"https://api.github.com/users/dritchie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dritchie/subscriptions","organizations_url":"https://api.github.com/users/dritchie/orgs","repos_url":"https://api.github.com/users/dritchie/repos","events_url":"https://api.github.com/users/dritchie/events{/privacy}","received_events_url":"https://api.github.com/users/dritchie/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-20T18:50:17Z","updated_at":"2015-03-24T15:08:22Z","closed_at":null,"body":"WebPPL is fine with compiling this code:\r\n```\r\nvar bar = function()\r\n{\r\n\treturn 42;\r\n}\r\n\r\nvar generate = function()\r\n{\r\n\treturn foo();\r\n}\r\n```\r\nbut when compiling this code:\r\n```\r\nvar wrap = function(fn)\r\n{\r\n\treturn fn;\r\n}\r\n\r\nvar foo = function()\r\n{\r\n\treturn bar();\r\n}\r\n\r\nvar bar = wrap(function()\r\n{\r\n\treturn 42;\r\n});\r\n\r\nvar generate = function()\r\n{\r\n\treturn foo();\r\n}\r\n```\r\nit dies with `Uncaught ReferenceError: bar is not defined`.\r\n\r\nInspecting the compiled code, it looks like `bar` is losing its name, because it no longer appears as a function declaration to the CPS transformation:\r\n```\r\nvar wrap = function (globalStore, _k3, address, fn) {\r\n        var _return = _k3;\r\n        _trampoline = function () {\r\n            _return(globalStore, fn);\r\n        };\r\n    };\r\n    var foo = function (globalStore, _k4, address) {\r\n        var _return = _k4;\r\n        var _s5 = address.concat('_1');\r\n        _trampoline = function () {\r\n            bar(globalStore, _return, _s5);\r\n        };\r\n    };\r\n    var _s10 = address.concat('_2');\r\n    var _s11 = function (globalStore, _k12, address) {\r\n        var _return = _k12;\r\n        _trampoline = function () {\r\n            _return(globalStore, 42);\r\n        };\r\n    };\r\n```\r\nIt's obnoxious to have to start worrying about function declaration order again in a language that's supposed to be agnostic to it. I get the need to use `_s` symbols when introducing new intermediates, but is there a reason why `bar` needs to be renamed in this case?"},"comment":{"url":"https://api.github.com/repos/probmods/webppl/issues/comments/85544198","html_url":"https://github.com/probmods/webppl/issues/61#issuecomment-85544198","issue_url":"https://api.github.com/repos/probmods/webppl/issues/61","id":85544198,"user":{"login":"ngoodman","id":461193,"avatar_url":"https://avatars.githubusercontent.com/u/461193?v=3","gravatar_id":"","url":"https://api.github.com/users/ngoodman","html_url":"https://github.com/ngoodman","followers_url":"https://api.github.com/users/ngoodman/followers","following_url":"https://api.github.com/users/ngoodman/following{/other_user}","gists_url":"https://api.github.com/users/ngoodman/gists{/gist_id}","starred_url":"https://api.github.com/users/ngoodman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ngoodman/subscriptions","organizations_url":"https://api.github.com/users/ngoodman/orgs","repos_url":"https://api.github.com/users/ngoodman/repos","events_url":"https://api.github.com/users/ngoodman/events{/privacy}","received_events_url":"https://api.github.com/users/ngoodman/received_events","type":"User","site_admin":false},"created_at":"2015-03-24T15:08:22Z","updated_at":"2015-03-24T15:08:22Z","body":"It's worth figuring out how CPS-based compilers for functional languages usually handle mutual recursion... Maybe @kimmyg knows?"}}