-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Disallow @macroname x, y? #12021
Comments
Hit this today, funnily enough. We do have this construct in JuMP though: @addConstraints mod begin
stuff
end Is that the same thing? We'd be happy to use the parentheses for this. |
Though @addConstraint(mod, begin
stuff
end) is better IMO. +1 to this. |
👍 This caused me trouble also |
@IainNZ That's not quite the same thing. But since you mention it, I wonder what the rationale is/was for allowing macro calls without parens. There is certainly a lot of code that calls macros without them, but I tend to agree that things are clearer with them. |
I think it allows for clearer code when using macros like But +1 for your proposal. |
@simonster This is definetly two different issues.
I like tuples without parentheses when the meaning is clear, but this issue seems to indicate that we should require parentheses when combined with macros. I like the possibility to have 1 argument macros without parentheses (eg |
-10¹⁰ for this, please don't. It's useful feature when using macros to create DSLs (like done by JuMP, ArgParse, etc.); differentiating between one and more args is inconsistent and annoying. (I have no problems in removing the parenthesis-less tuples in macro arguments even though I occasionally use them, the distinction is in fact subtle.) |
same as @carlobaldassi - DSLs like FunctionalData et al require the |
I agree |
In another word, I find both |
Personally I have a really hard time reading @rened's code that uses FunctionalData, when it's otherwise doing things that I would find useful. With the exception of the above This issue's primarily about the comma-vs-tuple confusion though. |
@tkelman yeah, I know, it looks very different. have to expand the documentation and add a tutorial. DSLs are always a tradeoff - another thing to learn, but they can make certain problems drastically easier to formulate / solve. I would not dare to heavily promote a pet DSL, but it would an absolute shame to loose the ability to implement/use them. back on topic, I believe disallowing the |
I don't have a problem with function foo(a,b,c)
....code....
expr1,
# comments
# blah, blah, blah
# blah, blah, blah
expr2
end The little comma above really changes everything. |
I've been pretty unhappy with using macros without parentheses for a long time since they require users to understand something subtle about how expression boundaries are defined in Julia. I really think we should discourage people building complex DSL's on top of Julia's more obscure pieces of syntax and encourage them to use string-parsing instead. As far as I can see, there's almost no cost to making most DSL macros invocations look like, |
@johnmyleswhite I agree, very good suggestion! But I would like to avoid the explicit string notation. That would feel as clumsy as "metaprogramming" in matlab or other interpreted languages and would be a huge step back. To have to put this around every line is tedious, multiline would be odd, you would loose syntax highlighting (numbers are still numbers, e.g.), etc. FWIW, I am not involved in the Building on @johnmyleswhite 's suggestion, what about the following: stringmacro mymacro(a::String)
...
end
$mymacro problem <-> specific -> notation This allows the parser to do whatever it wants in standard macros (like this issue proposes), and DSLs can be expressed with less hacks using Please let's not take away the wonderful, unique ability of Julia to write clean, custom DSLs for scientific computing. |
Glad you're sympathetic, @rened. Isn't what you're describing essentially equivalent to http://julia.readthedocs.org/en/latest/manual/metaprogramming/#non-standard-string-literals |
@johnmyleswhite Thanks for the link! Yes, except for the fact that strings are exactly the thing I want to avoid ;-) The semantic intent of a line should be obvious IMO ("is this a string/data? are these instructions?"). And syntax highlighting is really important for legibility. Try it out on a non-DSL piece of Julia code, and put 2/3rds of the lines in between So yes, what I am proposing is functionally the same as non-standard string literals, except for the string part. I know this feels like a detail if you don't need the functionality, but if suddenly most of your code is string literals... total nightmare. |
Some macro DSL's make that inherently non-local since you have to understand what the macro is doing and how it works. If the macro arguments are just a list of space-separated expressions, then syntax highlighting only makes a difference within each of the expressions. And any expressions that have any infix operators in them might be easily confused with the macro-argument-separator spaces. |
@tkelman regarding the topic discussed in this issue - yes, you are right, of course. My comment was more meant in response to @johnmyleswhite suggestion for generally handling DSLs using the |
Well, my opinion is pretty much diametrically opposed to what @johnmyleswhite said, so it boils down to personal preference I think. I could get into more detail but I don't expect it would be very profitable and it's not the main focus of this issue anyway.
|
I second the points @carlobaldassi made. |
I think this would need #7669 fixed. |
I think that the following rules should hold.
This would also fix #7669; |
I vote no. |
Let's not change this. |
It's not immediately obvious to many people that
@macroname x, y
will be parsed as@macroname((x, y))
and not@macroname(x), y
or@macroname(x, y)
. This has been a source of confusion for use of@compat
(JuliaLang/Compat.jl#71, JuliaLang/Compat.jl#111, JuliaLang/Compat.jl#116, JuliaLang/Compat.jl#136, probably other places as well), but I'm not sure I've ever seen it used intentionally. In the interest of usability, we might just want to throw an error.cc @sbromberger
The text was updated successfully, but these errors were encountered: