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

Macros called with parens can have arguments parsed as keywords #7669

Closed
timholy opened this issue Jul 19, 2014 · 6 comments
Closed

Macros called with parens can have arguments parsed as keywords #7669

timholy opened this issue Jul 19, 2014 · 6 comments
Assignees
Labels
breaking This change will break code needs decision A decision on this change is needed parser Language parsing and surface syntax
Milestone

Comments

@timholy
Copy link
Member

timholy commented Jul 19, 2014

Not sure whether this is intended, but it did surprise me:

macro showheads(arg1, arg2)
    @show arg1.head
    @show arg2.head
    :nothing
end

julia> @showheads (1,2) (x = 5)
arg1.head => :tuple
arg2.head => :(=)

julia> @showheads((1,2), (x = 5))
arg1.head => :tuple
arg2.head => :kw

Using 0.3.0-rc1.

@timholy timholy changed the title Macros called with parens can be parsed as keywords Macros called with parens can have arguments parsed as keywords Jul 19, 2014
@StefanKarpinski
Copy link
Member

Ah, that's an interesting corner case. The macro parser with parens just reuses the function call parsing logic, which has occasionally caused some issues like this.

@jakebolewski
Copy link
Member

Yeah we probably need a macro parsing context to resolve Function / macro differences.

@JeffBezanson
Copy link
Member

I don't think it's super surprising that this parses like a function call.

@timholy
Copy link
Member Author

timholy commented Jul 21, 2014

It's not super-surprising, but I think there's a temptation to think of @cmd a b and @cmd(a,b) as meaning the same thing.

@tpapp
Copy link
Contributor

tpapp commented Oct 6, 2014

I recently ran into this, trying to implement someting like the CL macro

(defmacro invisible (&body body)
  `(progn ,@body (values))

in Julia as

macro invisible(expressions...)
  quote
    $(expressions...)
    nothing
  end
end

and got

julia> @invisible a=1
julia> @invisible(a=1)
ERROR: unsupported or misplaced expression kw

It would be great if the two forms parsed the same way.

@JeffBezanson JeffBezanson added the parser Language parsing and surface syntax label Mar 16, 2015
@Tetralux
Copy link
Contributor

Ref #12021;
@foo((1,2), (x = 5)) and @foo (1,2) (x = 5) should both pass (1, 2) and :(x = 5) to the macro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code needs decision A decision on this change is needed parser Language parsing and surface syntax
Projects
None yet
Development

No branches or pull requests

6 participants