3 ms·
There are many languages that use = for assignment and == for comparison, without the possibility of confusing the two. In Python, for example, assignment is no
by int_19h 10y ago
There are many languages that use = for assignment and == for comparison, without the possibility of confusing the two. In Python, for example, assignment is not an operator at all, so using it in expression context is invalid.
Which leaves the distinction between assignment and comparison - which is always there - as the only reason to have two distinct operators. Which ones they are becomes a matter of taste, but as I recall, the reason why C settled on = for assignment is because it's that much more common. This is still the case today, even in pure languages where it's used for bindings only.
- quickben 10y agoWell, it's similar to math and that was there long before lisp or C
- int_19h 10y agoMath notation uses := for assignment and = for equality, no? So in that sense Algol and the Pascal family are more consistent with that, while C actually diverged.
- majewsky 10y agoDepends on your field. Some math subjects would argue that "assignment" does not exist, because the same name within the same scope always refers to the same value, whether it's known or not. Within algorithms, I'm most used to "<-" for assignment, for example "i <- i + 1" inside a loop to count iterations.
- qwertyuiop924 10y agoWell, in lisp making assignment a statement is a non-option: statements don't exist. The closest thing is returning #<unspecified> in scheme.