-
-
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
permit a<space>.b syntax, if possible #17305
Comments
If you're making a macro dsl, you should probably use an infix operator. |
@tkelman From my perspective, |
This was discussed extensively in #11891 and #7232. Since julia doesn't require semicolons at the ends of statements, the pattern
doesn't work well because after
|
@xitology but an infix operator that doesn't allow spaces ;) Is there any reason not to use |
My (ab)use of Julia syntax is certainly unorthodox and I'm sure will be frowned upon by Julia developers. The That said, I don't want to make it a discussion of my stylistic choices in DSL design. This is hardly a great argument for changing language parser. I just used it as one example where one might prefer method-chaining. As opposed to
Indeed, you could write
but I think the former is more stylistically appropriate and would be the first choice for most programmers. I don't know if it interferes with other language features (like |
I'm sorry for spamming this issue, but here's another argument. Even though currently method-chaining APIs for Julia do not exist, it looks like you are going to enable overriding the attribute access operator (see #1974). If so, I'm sure method-chaining APIs will appear even without macros, so this issue will probably be raised again. |
There doesn't seem to be anything actionable here. |
@JeffBezanson Is it that it would be inconvenient in the parser to support this, or that it's just plain impossible to support? This is a particularly important case for us for code ergonomics reasons. |
It's certainly possible; indeed we allowed it prior to v0.4. We decided to remove it in #11891, but it seems to me the argument there wasn't overwhelming, and indeed a couple people said we might want to revisit this if we added dot overloading, which we did. Could you give an example of the specific syntax you'd like to use? One thing we probably cannot support is
However it already works if you put the dots at the end of lines:
Some people seem to consider that completely unacceptable, but that seems overly fussy to me. |
Would it be possible to at least allow parsing the former syntax inside of parens? In either case, it would be a nonbreaking change. |
If we removed the rule about spaces before dots, yes, I think that would just work. People will surely then try it in statement position though. |
First, thank you for looking again at this ticket. As Kyrylo noted above, our primary use case is "abusing" the @macro syntax parser in order to construct a familiar "fluent interface". As such, I don't think using leading periods "in statement position" would be particularly common. Currently, we have single line queries, such as below.
As the queries get much longer and involved, we'd like a way to make them multi-line. Of course, we could ask users to use the period at the end of each line, as Jeff noted. I don't think it is particularly nice to read or customary. Further, as you append new operators to the end, you have to modify the previous line for the trailing period, and hence it shows up as 2 lines changed in source code control rather than a single insertion. Here's how we'd prefer to line-break the previous query for readability.
One potential alternative is the begin/end variant. However, I can't collapse it all into a single line without adding periods; this is an odd rule to explain to casual users. That said, adding another query in the chain doesn't involve modifying previous lines. So, this is probably the alternative we'd promote if leading-periods is not permitted.
We have tried to use |
Ok, we can make the parenthesized |
Kyrylo also mentioned it's usefulness in regular function calls.
Is this the same production? Also, I think Kyrylo noted that |
Yes. |
Julia 0.4 deprecated and Julia 0.5-dev made an error the
a<space>.b
syntax:It prevents me from using a "method-chaining" pattern, which is common in some languages and frameworks:
Admittedly, it is less common in Julia as it lacks special method syntax, but I happen to use it in my experimental Julia-based query DSL:
It is possible to un-deprecate this syntax? I found the original commit 28e7bd4, but it has no justification for deprecating it in the first place.
The text was updated successfully, but these errors were encountered: