2 ms·
There really isn't a syntax problem. All you have to do is, assuming you're in whitespace-oblivious mode due to being inside `()` or something, switch back to i
by o11c 3y ago
There really isn't a syntax problem. All you have to do is, assuming you're in whitespace-oblivious mode due to being inside `()` or something, switch back to indentation-based lexing after the `:` of a `def` or `class`, and end once it dedents or you reach (but do not consume) a close paren (of course, after the close paren you might end up enabling indentation mode again).
I'm not sure what style guides would declare the correct formatting to be, but this would not confusing to the parser at least:
some_function(def f(a):
return a # comma must be on the next line unless you add parentheses
, def g(b):
return b)
Note that `lambda:` and `slice[:]` are different uses of the colon, and `wal := rus` is a different token.
- shiomiru 3y agoIndeed. Nim also has significant whitespace, and your example translated: proc some_function(a, b: proc(a: int): int) = echo a(1) echo b(2) some_function(proc(a: int): int = return a , proc(b: int): int = return b) is valid Nim and compiles just fine. (Also, "1, 2" is not valid Nim, so unlike with Python you can just put the comma right after `a' without syntactic ambiguity.)
- o11c 3y agoFollowing the aside ... requiring parentheses around tuples is generally best for readability. I can only think of two cases that are more readable without them: (x, y) = (y, x) some_array[(x, y)] Languages generally already special-case both the LHS of assignments and the inside of indexing brackets, and special-casing the RHS of assignments seems like a reasonable extension.
- cb321 3y agoTo amplify your "comma right after", the call can even be simply: some_function(proc(a: int): int = a, proc(b: int): int = b) And Nim lets you put ()s in a great many places to resolve problems. I find its syntax quite a bit nicer than Python, actually.