{"action":"created","issue":{"url":"https://api.github.com/repos/welliam/scheme-to-js/issues/6","repository_url":"https://api.github.com/repos/welliam/scheme-to-js","labels_url":"https://api.github.com/repos/welliam/scheme-to-js/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/welliam/scheme-to-js/issues/6/comments","events_url":"https://api.github.com/repos/welliam/scheme-to-js/issues/6/events","html_url":"https://github.com/welliam/scheme-to-js/issues/6","id":190217651,"number":6,"title":"Definition behavior","user":{"login":"welliam","id":4933194,"avatar_url":"https://avatars.githubusercontent.com/u/4933194?v=3","gravatar_id":"","url":"https://api.github.com/users/welliam","html_url":"https://github.com/welliam","followers_url":"https://api.github.com/users/welliam/followers","following_url":"https://api.github.com/users/welliam/following{/other_user}","gists_url":"https://api.github.com/users/welliam/gists{/gist_id}","starred_url":"https://api.github.com/users/welliam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/welliam/subscriptions","organizations_url":"https://api.github.com/users/welliam/orgs","repos_url":"https://api.github.com/users/welliam/repos","events_url":"https://api.github.com/users/welliam/events{/privacy}","received_events_url":"https://api.github.com/users/welliam/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-18T02:05:35Z","updated_at":"2016-11-18T08:23:01Z","closed_at":null,"body":"These should all work:\r\n```scheme\r\n(let ()\r\n  (define x 0)\r\n  (define y 1)\r\n  (+ x y))\r\n\r\n(define (f)\r\n  (define (even? x) (or (zero? x) (odd? (- x 1))))\r\n  (define (odd? x) (and (not (zero? x)) (even? (- x 1))))\r\n  (display \"checking whether 16 is even...\")\r\n  (newline)\r\n  (even? 16))\r\n\r\n(begin\r\n  (define foo 1)\r\n  (define quux 2))\r\n```\r\nThe first two should compile similarly, as let and the defun-style define should both compile to lambdas, which expand to use begin. While all of them use begin, the behavior of the last example is important. Currently, begin sequences using function application, where the values being applied to are the expressions in sequence. This won't work because we introduce new scopes using this method, and the definition won't affect top level scope. Secondarily, because we use semicolons in code generated from define, using defines in such a way will generate invalid JS.\r\n\r\nWe could attempt to eliminate all inner level definitions, replacing them with letrecs. The third case would have to be handled separately, perhaps as a simple chaining of statements using semicolons.\r\n\r\nShould the following even be accepted by the compiler?\r\n```scheme\r\n(display (define x 0))\r\n\r\n(or (define x 0) 1)\r\n\r\n(or (define x 0) x)\r\n```\r\nRacket rejects all, reporting \"define: not allowed in an expression context\", which seems most reasonable."},"comment":{"url":"https://api.github.com/repos/welliam/scheme-to-js/issues/comments/261474554","html_url":"https://github.com/welliam/scheme-to-js/issues/6#issuecomment-261474554","issue_url":"https://api.github.com/repos/welliam/scheme-to-js/issues/6","id":261474554,"user":{"login":"welliam","id":4933194,"avatar_url":"https://avatars.githubusercontent.com/u/4933194?v=3","gravatar_id":"","url":"https://api.github.com/users/welliam","html_url":"https://github.com/welliam","followers_url":"https://api.github.com/users/welliam/followers","following_url":"https://api.github.com/users/welliam/following{/other_user}","gists_url":"https://api.github.com/users/welliam/gists{/gist_id}","starred_url":"https://api.github.com/users/welliam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/welliam/subscriptions","organizations_url":"https://api.github.com/users/welliam/orgs","repos_url":"https://api.github.com/users/welliam/repos","events_url":"https://api.github.com/users/welliam/events{/privacy}","received_events_url":"https://api.github.com/users/welliam/received_events","type":"User","site_admin":false},"created_at":"2016-11-18T08:23:01Z","updated_at":"2016-11-18T08:23:01Z","body":"Top level begins could be spliced into the program as-is. This would ensure that all defines which occur within begins are not top level. This would allow for the letrec method to be more easily written."}}
{"actor":{"display_login":"welliam"}}