On Feb 2, 2020, at 09:14, Johan Vergeer <johanvergeer@gmail.com> wrote:

Thank you so much for this concrete proposal. I could not have described it clearer myself.

I'm not sure about leaving out the parentheses. But this is mostly out of preference. Especially since Python also has a `type()` function.

But that’s the whole point: type is a function, and nameof is something totally different from a function. 

(Actually, type is a type whose constructor does something different from constructing an object when passed a single param, but never mind that bit.)

Making it look like a function call makes sense for a C family language—function calls, macro calls, old-style annotations (like declspec in Microsoft C), and compile-time operators like sizeof all use the same syntax, and nameof is just like sizeof, so why shouldn’t it look the same?

Making it look like a function call in Python wouldn’t make sense. In Python, while you can call all kinds of things (functions, types, objects whose types define __call__) with the same syntax, they always have the same semantics: at runtime, call the value on the left with the values of the things inside parens as parameters. Something with radically different semantics (that doesn’t even evaluate the value of the “parameter”) using the same syntax would be confusing.

Out of personal curiosity: Is the way you described the grammar an official notation, and if so, could you give me a link to some documentation


It’s the almost-BNF notation used in the Python docs. See https://docs.python.org/3/reference/introduction.html#notation for details.

If you haven’t skimmed the reference docs, they do a pretty good job explaining the semantics that goes with each construction, the underlying data model, etc. in terms that make sense to Python programmers (as opposed to, e.g., the C spec, which is only intended to make sense to people writing C compilers).