Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Operator associativity
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Non-associative operators == Non-associative operators are operators that have no defined behavior when used in sequence in an expression. In [[Prolog]] the infix operator <code>:-</code> is '''non-associative''' because constructs such as "<code>a :- b :- c</code>" constitute syntax errors. Another possibility is that sequences of certain operators are interpreted in some other way, which cannot be expressed as associativity. This generally means that syntactically, there is a special rule for sequences of these operations, and semantically the behavior is different. A good example is in [[Python (programming language)|Python]], which has several such constructs.<ref>''[https://docs.python.org/3/reference/ The Python Language Reference],'' "[https://docs.python.org/3/reference/expressions.html 6. Expressions]"</ref> Since assignments are statements, not operations, the assignment operator does not have a value and is not associative. [[Assignment (computer science)#Chained assignment|Chained assignment]] is instead implemented by having a grammar rule for sequences of assignments <code>a = b = c</code>, which are then assigned left-to-right. Further, combinations of assignment and augmented assignment, like <code>a = b += c</code> are not legal in Python, though they are legal in C. Another example are comparison operators, such as <code>></code>, <code>==</code>, and <code><=</code>. A chained comparison like <code>a < b < c</code> is interpreted as <code>(a < b) and (b < c)</code>, not equivalent to either <code>(a < b) < c</code> or <code>a < (b < c)</code>.<ref>''[https://docs.python.org/3/reference/ The Python Language Reference],'' "[https://docs.python.org/3/reference/expressions.html 6. Expressions]": [https://docs.python.org/3/reference/expressions.html#comparisons 6.9. Comparisons]</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)