3 ms·
What db48x neglected to mention is that some of those languages also featured assignment as strictly a statement; it could not be a subexpression. As in: fu
by kazinator 6y ago
What db48x neglected to mention is that some of those languages also featured assignment as strictly a statement; it could not be a subexpression. As in:
fun(x := 42); (* syntax error in Pascal *)
x := 42; (* OK *)
x = 42; (* hopefully a statement with no effect warning *)
If assignment is a statement, it's possible to use the same token. Classic BASIC:
10 X = 5
20 IF X = 5 GOTO 10
This doesn't cause the C problem of mistaken assignment in place of a test, so it's rather ironic that C managed to shoot itself in the foot in spite of dedicating twice the number of tokens.
- db48x 6y agoI'd forgotten that!
- a1369209993 6y agoThat is true, but has nothing to do with "==" vs "=" vs ":=". You can do: func(x = 42); /* syntax error: expression operator expected, got '=' */ x = 42; /* OK */ x == 42; /* warning: statement expression has no effect */ just fine if you require "=" to be a statement.