Was there any specific reason for the current template syntax?
Mojo currently uses the
[
and ]
characters to specify templates instead of the <
and >
characters that we see in most other languages.
Initially one would think it is to avoid the known ambiguity the latter characters can cause, however the current characters also make the grammar ambiguous.
In all of these cases the syntax is identifier[literal]()
, but every case parses into a different AST. So I wonder if there was any specific reason for choosing the current syntax or it was only for using different tokens than <
and >
.5 Replies
It's actually the python syntax, mojo isn't inventing anything here: https://peps.python.org/pep-0695/ and https://peps.python.org/pep-0718/
PEP 695 – Type Parameter Syntax | peps.python.org
Python Enhancement Proposals (PEPs)
PEP 718 – Subscriptable functions | peps.python.org
Python Enhancement Proposals (PEPs)
I see. I wasn't aware that python had such proposals.
Thanks for the answer
i've just realized thats why i keep writing list(int) and it doesnt work
yeah python should ve made it <>
Could do clarify what does that refers to in this sentence?
i kept writing list(int) and it doesnt say error but type hinting didnt work and i keep forgetting if it is list(int) or list[int]