Skip to content
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

Built-in operators and their precedence #271

Open
eyelash opened this issue Feb 2, 2025 · 2 comments
Open

Built-in operators and their precedence #271

eyelash opened this issue Feb 2, 2025 · 2 comments
Labels
doc-request Request for missing documenation

Comments

@eyelash
Copy link
Contributor

eyelash commented Feb 2, 2025

It's possible that I somehow missed it but I couldn't find a list of all the built-in operators (like +, -, %, <, etc.) with their relative precedence and associativity.

Here are some examples from other languages to get a better idea of what I'm looking for:

I believe the list of operators for Lean can be found here.

@eyelash eyelash added the doc-request Request for missing documenation label Feb 2, 2025
@david-christiansen
Copy link
Collaborator

A table of operators is a bit more interesting in Lean, because the syntax is extensible. The set of available operators can depend on which libraries have been imported and which namespaces are opened.

That said, a table of all the operators that ship with Lean sounds useful.

In what concrete way would this help you get your work done?

@eyelash
Copy link
Contributor Author

eyelash commented Feb 3, 2025

It doesn't necessarily have to be a table, just a single place where all the built-in operators are listed.

This would help me as follows:

When reading code, I might come across an expression such as 1 <<< 2 + 3 and I might wonder what <<< does or whether this expression is parsed as (1 <<< 2) + 3 or 1 <<< (2 + 3). Having a page in the reference manual where all the built-in operators are listed together with their precedence would allow me to quickly answer this question. Note that when I'm reading code I might not have access to IDE features such as go-to-definition since the code might be on GitHub or StackOverflow for example.

While writing code or learning the language, I want to know which operators are available at my disposal so that I can write my code in an optimal way. Having all the built-in operators listed in a single place would help me learn the language, especially since Lean is a functional language that comes with a few operators (>>=, >>, <*>, etc.) that might not be familiar to people coming from other languages.

The reference manual might not be the right place for such a list but having such a list somewhere would definitely be very helpful to me.

A table of operators is a bit more interesting in Lean, because the syntax is extensible. The set of available operators can depend on which libraries have been imported and which namespaces are opened.

It might be worth taking a look at the documentation for Swift, since it also allows you to define custom operators. Their documentation is split into two pages:

  • Basic Operators explains what an operator is and then lists assignment (=, +=, etc.), arithmetic (+, *, etc.), comparison (==, <, etc.), logical (!, &&, ||), ternary conditional, nil-coalescing, and range operators.
  • Advanced Operators explains bitwise and overflow operators, precedence and associativity, and how to create custom operators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-request Request for missing documenation
Projects
None yet
Development

No branches or pull requests

2 participants