-
Notifications
You must be signed in to change notification settings - Fork 23
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
Allow to indent of/else/elif/except/finally
for block commands
#420
Comments
The way to write the case statement is: case variable
of value1, value2: ... No additional indentation and no colon after Likewise we only need to support match arg
of test1: discard
of test2: discard
elif 12: discard
except: discard
else: discard IMO. But I still like the overloaded |
match arg:
myof ...
match arg:
of ...
case arg:
of ..
case arg:
of ... Are allowed, but match arg:
of ... Is not allowed. If we disregard stylistic preferences about number of spaces before 'of', optionally of the colon, we still have this inconsistency where parsing of the 'of' branches differs between case statement and user commands. Both allow to use branches, but one supports indent, and other does not. Also, match arg:
myof ... Is the only way to write it, because match arg:
myof ... Is not valid. |
What about the reasoning for the |
How about, instead, deprecating |
Okay, got it, stylistic preferences etc. Don't think there is any reason to keep this RFC open then, probably won't be accepted anyway. |
Why reopen? It seems like most responses would be "no, because I don't like to indent 'of'" (i.e. this will turn into stylistic holywar without addressing any other points). |
Well it's not a bad idea in itself. I merely happen to dislike it but not strongly enough. Plus my own proposal ( |
Got it. I reopened PR then, its CI is green and fix itself is ~7 lines, so it is mostly a yes/no decision in the RFC about whether we want this in the language. |
I am neutral, but I want Pattern Matching more close to StdLib, |
Pattern matching in stdlib also should wait for (1) |
I'd prefer pattern matching to be available as a non-standard library module first, and then later incorporated into the standard library. That way we have some definite evidence regarding which design or approach works best. |
@Varriount and that's exactly why I decided to add pattern matching to fusion first, so everyone could test it out and see what is working and what is not. Over the past 11 months since I made my PR nim-lang/fusion#33 I didn't have any major complaints with design, things that people did complain about were mostly about missing functionality, or lack of docs for certain parts, which I also tried to fix in timely manner. Overall, I think my specification from #245 worked well enough, with the only noticeable inconvenience being that there can be only one implementation of the patter matching in a given scope, and it would implicitly change the semantics of the built-in language construct based on the switch expression type. Which is, IMO, quite questionable. Also, if you have any specific complaints about pattern matching implementation you can open the issue in fusion, or comment on #245, or tag me on any of the real-time chats (that's where a noticeable portion of fusion improvements were designed). |
I also did make a PR nim-lang/Nim#17047 into stdlib when fusion was unbundled from nim, but was told (in discord discussion that followed) that "well if you want it in the standard, it should look exactly as we want it", (in context of let expressions https://irclogs.nim-lang.org/15-02-2021.html#18:49:45). I agree that we need to wait for let expressions, and some other things, and after all I decided to close the PR because "current implementation can be improved in certain areas, and regardless whether we would get it into stdlib at some point, it would differ from this PR" nim-lang/Nim#17047 (comment) And while view types and let expressions are relatively huge, 'match' syntax requires 7 line fix in the compiler, and would make it possible to write macros that provide completely seamless syntactic interoperability with 'case'. Without any new features, implicit type-based change-semantics-of-basic-constructs, must-use-experimental-feature solutions. |
What would a parser fix that allows for |
Just to make sure, you mean this, right? match arg
of test Well in my PR I just expand match arg1, arg2
of 1: discard
match arg1 = test
of 1: discard This can probably be done, though I don't understand why we need to get rid of colon delimiter for this, since every single block statement uses it - Also, how it should treat myMacro 123
myOf 12: discard I imagine it should be the same, or somehow considered as well? |
Right.
Because
Not for me, no, |
So you want to make match arg
of 12: ...
else: ...
match arg:
of 12: ...
else: ...
match arg:
of 12: ...
else: ...
match arg
of 12: ...
else: ... |
And note that indenting match(a):
Rectangle: # matches Rectangle(a: 0), Rectangle(a: 2, b: 4)
echo "rectangle"
_:
echo "other" and so did patty https://github.com/andreaferretti/patty#example proc sum(xs: List[int]): int = (block:
match xs:
Nil: 0
Cons(y, ys): y + sum(ys[])
) |
I only care about match arg
of 12: ...
else: ... The other forms can be supported for consistency, but I don't care. :-) |
Alright, if we can agree on supporting all forms mentioned above, I will expand my PR if possible. Can I treat your reply as "Let's see what it breaks accepted RFC" |
We can agree on that, yes. |
|
I think the language should be fixed to require |
We already support too much random AST arrangements, so fixing them is nearly impossible. import std/macros
dumpTree:
match if a: a
else: b:
if c:
c
else: d
myof: zzz
of a: q
That does not make sense to me (I don't really know what should "correct" AST look like for this code. (Colon after b is supposed to close post expr block for match, so second if should be in the main body, but it got parser into call for 'b' for some reason.)), I assume it does not make sense to you either, but I'm pretty sure there is a line somewhere (maybe even in important packages) that relies on this behavior. Replacing import std/macros
dumpTree:
match bbb:
if c:
c
else: d
myof: zzz
of a: q
|
As long as the code breakage isn't silent I don't mind it too much. We need to have a 2.0 release anyway for |
Assessing damage done by parser changes is relatively easy and can be done for whole ecosystem (at least it was not particularly time-consuming to parse all existing code to figure out stdlib usages), so we can make an informed decision when it comes to considering this change. |
Proposal is pretty simple - allow additional level of indentation for command calls:
This topic came up several times in discussion of
caseStmtMacros
. Main reason for this change - there should be only onecase
in the language, and implicitly overloading it with multiple different semantics is not the best idea<macro-related error>
" would probably confuse every possible syntax at once),Instead, being able to write a custom macro that looks like case is much easier, but right now
case
allows for indentedof
, but command block doesn't. This is probably the only limitation, it is pretty minor, but still annoying because of random inconsistencies.Related
case
#332The text was updated successfully, but these errors were encountered: