{"action":"created","issue":{"url":"https://api.github.com/repos/jackfirth/generic-syntax-expanders/issues/8","repository_url":"https://api.github.com/repos/jackfirth/generic-syntax-expanders","labels_url":"https://api.github.com/repos/jackfirth/generic-syntax-expanders/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/jackfirth/generic-syntax-expanders/issues/8/comments","events_url":"https://api.github.com/repos/jackfirth/generic-syntax-expanders/issues/8/events","html_url":"https://github.com/jackfirth/generic-syntax-expanders/pull/8","id":172931590,"number":8,"title":"Remove the extra use-site scope on the body of define-?-expander.","user":{"login":"jsmaniac","id":299872,"avatar_url":"https://avatars.githubusercontent.com/u/299872?v=3","gravatar_id":"","url":"https://api.github.com/users/jsmaniac","html_url":"https://github.com/jsmaniac","followers_url":"https://api.github.com/users/jsmaniac/followers","following_url":"https://api.github.com/users/jsmaniac/following{/other_user}","gists_url":"https://api.github.com/users/jsmaniac/gists{/gist_id}","starred_url":"https://api.github.com/users/jsmaniac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsmaniac/subscriptions","organizations_url":"https://api.github.com/users/jsmaniac/orgs","repos_url":"https://api.github.com/users/jsmaniac/repos","events_url":"https://api.github.com/users/jsmaniac/events{/privacy}","received_events_url":"https://api.github.com/users/jsmaniac/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-08-24T11:50:16Z","updated_at":"2016-08-24T11:54:56Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/jackfirth/generic-syntax-expanders/pulls/8","html_url":"https://github.com/jackfirth/generic-syntax-expanders/pull/8","diff_url":"https://github.com/jackfirth/generic-syntax-expanders/pull/8.diff","patch_url":"https://github.com/jackfirth/generic-syntax-expanders/pull/8.patch"},"body":"When a macro is expanded, Racket adds an extra use-site scope. If the first macro expands to a second macro definition, this scope should however be removed, as it is otherwise present on syntax objects created by the second macro definition. For example, in the following file, the definitions of `bar1` and `bar2` are not identical, despite the fact that `foo` is just a thin wrapper around `define-syntax`: the syntax object created by `bar1` has an extra use-site scope.\r\n\r\n```racket\r\n#lang racket\r\n\r\n(define-syntax-rule (define-foo name . body)\r\n  (define-syntax name . body))\r\n\r\n(define-foo bar1\r\n  (λ (_)\r\n    (displayln (hash-ref (syntax-debug-info #'here) 'context))\r\n    #'(void)))\r\n\r\n(define-syntax bar2\r\n  (λ (_)\r\n    (displayln (hash-ref (syntax-debug-info #'here) 'context))\r\n    #'(void)))\r\n\r\n(bar1) ;; (#(1336773 module) #(1336774 module anonymous-module 0) #(1336871 use-site))\r\n(bar2) ;; (#(1336773 module) #(1336774 module anonymous-module 0))\r\n```\r\n\r\nIf instead we remove the use-site scope from the `bar1` definition (with `syntax-local-identifier-as-binding`), then the two macros `bar1` and `bar2` behave identically:\r\n\r\n```racket\r\n#lang racket\r\n\r\n(define-for-syntax (remove-use-site-scope stx)\r\n  (define bd\r\n    (syntax-local-identifier-as-binding (syntax-local-introduce #'here)))\r\n  (define delta\r\n    (make-syntax-delta-introducer (syntax-local-introduce #'here) bd))\r\n  (delta stx 'remove))\r\n\r\n(define-syntax (define-foo stx)\r\n  (syntax-case stx ()\r\n    ([_ name . body]\r\n     (remove-use-site-scope #'(define-syntax name . body)))))\r\n\r\n(define-foo bar1\r\n  (λ (_)\r\n    (displayln (hash-ref (syntax-debug-info #'here) 'context))\r\n    #'(void)))\r\n\r\n(define-syntax bar2\r\n  (λ (_)\r\n    (displayln (hash-ref (syntax-debug-info #'here) 'context))\r\n    #'(void)))\r\n\r\n(bar1) ;; (#(1332508 module) #(1332509 module anonymous-module 0))\r\n(bar2) ;; (#(1332508 module) #(1332509 module anonymous-module 0))\r\n```\r\n\r\nNote that it is necessary to remove the scope when defining `bar1`, as the body of `bar1` itself can't do much about it, as the extra scope is present on all parts of its syntax. In a way, `bar1` behaves a bit as if it were defined inside a `let` form: removing the scope added by `let` from withing `bar1` would be very difficult, as `bar1` would be stuck inside the `let`, and could not easily see the scopes present on the \"outside world\", which makes it very difficult to pinpoint that exact extra scope.\r\n\r\nThis patch applies the same fix to the definition of `define-?-expander`.\r\n\r\nWithout this patch, it is difficult to define two expanders which communicate with one another: definitions introduced by the first will have the use-site scope `1234`, while uses produced by the other will have the use-site scope `1235`, and therefore won't be `bound-identifier=?` anymore."},"comment":{"url":"https://api.github.com/repos/jackfirth/generic-syntax-expanders/issues/comments/242037644","html_url":"https://github.com/jackfirth/generic-syntax-expanders/pull/8#issuecomment-242037644","issue_url":"https://api.github.com/repos/jackfirth/generic-syntax-expanders/issues/8","id":242037644,"user":{"login":"coveralls","id":2354108,"avatar_url":"https://avatars.githubusercontent.com/u/2354108?v=3","gravatar_id":"","url":"https://api.github.com/users/coveralls","html_url":"https://github.com/coveralls","followers_url":"https://api.github.com/users/coveralls/followers","following_url":"https://api.github.com/users/coveralls/following{/other_user}","gists_url":"https://api.github.com/users/coveralls/gists{/gist_id}","starred_url":"https://api.github.com/users/coveralls/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coveralls/subscriptions","organizations_url":"https://api.github.com/users/coveralls/orgs","repos_url":"https://api.github.com/users/coveralls/repos","events_url":"https://api.github.com/users/coveralls/events{/privacy}","received_events_url":"https://api.github.com/users/coveralls/received_events","type":"User","site_admin":false},"created_at":"2016-08-24T11:54:56Z","updated_at":"2016-08-24T11:54:56Z","body":"\n[![Coverage Status](https://coveralls.io/builds/7585062/badge)](https://coveralls.io/builds/7585062)\n\nCoverage increased (+0.2%) to 74.453% when pulling **c4a872e63d9564f188caa6656db1f845633a67e8 on jsmaniac:fix-use-site-scope** into **4df442f59f12ca7bbb97cbfad22e3635f8dd9e59 on jackfirth:master**.\n"}}
{"actor":{"display_login":"coveralls"}}