Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro hygiene only protect you in different modules. #14893

Closed
Ismael-VC opened this issue Feb 1, 2016 · 1 comment · Fixed by #15850
Closed

Macro hygiene only protect you in different modules. #14893

Ismael-VC opened this issue Feb 1, 2016 · 1 comment · Fixed by #15850
Assignees

Comments

@Ismael-VC
Copy link
Contributor

This was reported at Stack Overflow:

   _       _ _(_)_     |  By greedy hackers for greedy hackers
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _' |  |
  | | |_| | | | (_| |  |  Version 0.5.0-dev+2446 (2016-02-01 14:54 UTC)
 _/ |\__'_|_|_|\__'_|  |  custom/a9c732a (fork: 2 commits, 0 days)
|__/                   |  Arch Linux x86_64

julia> macro g(y)
           :((x, $y, $(esc(y))))
       end

       x = 1
       function t()
           x = 2
           println(macroexpand(:(@g(x))))
           println(@g(x))
       end

       t()
       println(x)
(x,x,x)
(2,2,2)
1

julia> workspace()

julia> module A
       macro g(y)
           :((x, $y, $(esc(y))))
       end
       x = 1
       end

       x = 3

       function t()
           x = 2
           println(macroexpand(:(A.@g(x))))
           println(A.@g(x))
       end

       t()
(A.x,A.x,x)
(1,1,2)

I had expected the result to be (1, 1, 2).

However, if I define the macro in a different module, it works as expected.

Seems the hygiene simply prefix the symbols with the module namespace. Therefore it is impossible for the macro expander to distinguish different scopes in the first case.

yuyichao added a commit that referenced this issue Jun 1, 2016
* Allow assigning to `GlobalRef`.
* Allow defining/extending function with `GlobalRef`.
* Convert `GlobalRef` back to flisp.

Closes #14893
yuyichao added a commit that referenced this issue Jun 1, 2016
* Allow assigning to `GlobalRef`.
* Allow defining/extending function with `GlobalRef`.
* Convert `GlobalRef` back to flisp.

Closes #14893
yuyichao added a commit that referenced this issue Jun 20, 2016
* Allow assigning to `GlobalRef`.
* Allow defining/extending function with `GlobalRef`.
* Convert `GlobalRef` back to flisp.

Closes #14893
@JeffBezanson JeffBezanson self-assigned this Aug 15, 2016
@JeffBezanson
Copy link
Member

Duplicate of #4873

yuyichao added a commit that referenced this issue Dec 6, 2016
* Allow assigning to `GlobalRef`.
* Allow defining/extending function with `GlobalRef`.
* Convert `GlobalRef` back to flisp.

Closes #14893
yuyichao added a commit that referenced this issue Dec 6, 2016
* Allow assigning to `GlobalRef`.
* Allow defining/extending function with `GlobalRef`.
* Convert `GlobalRef` back to flisp.

Closes #14893
yuyichao added a commit that referenced this issue Dec 6, 2016
* Convert `GlobalRef` back to flisp.

Closes #14893
yuyichao added a commit that referenced this issue Dec 6, 2016
* Convert `GlobalRef` back to flisp.

Closes #14893
yuyichao added a commit that referenced this issue Dec 7, 2016
* Convert `GlobalRef` back to flisp.

Closes #14893
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants