flaps@dgp.toronto.edu (Alan J Rosenthal) (09/18/89)
rhg@cpsolv.UUCP (Richard H. Gumpertz) writes: >As long as we are discussing missing "assignment" operators, you might ponder >the lack of unary assignment operators. Why should I have to say X = -X or >X = ~X? Why not have unary assignment operators (ala ++ and --) for negation >and complement? I suppose a new syntax would have to be invented, but it >might be useful at times. A somewhat consistent but fairly bizarre syntax would be x -=; The analogy to x -= y is that x fn= y; expands to x = fn(x, y); so x fn=; expands to x = fn(x); ajr
karzes@mfci.UUCP (Tom Karzes) (09/19/89)
In article <1989Sep17.150504.16643@jarvis.csri.toronto.edu> flaps@dgp.toronto.edu (Alan J Rosenthal) writes: >A somewhat consistent but fairly bizarre syntax would be > x -=; > >The analogy to x -= y is that > x fn= y; >expands to > x = fn(x, y); >so > x fn=; >expands to > x = fn(x); The problem with this is that you would like it to have the same precedence as ++ and --. This causes the following: a -= * b to be parsed as: (a -=) * b rather than: a -= (* b) which is the current correct parse (and which should remain the correct parse). You'd have to introduce a new operator to make this work reasonably.
c05_ta06@jhunix.HCF.JHU.EDU (Ta06) (09/19/89)
>>A somewhat consistent but fairly bizarre syntax would be >> x -=; >The problem with this is that you would like it to have the same precedence >as ++ and --. ... Why? We don't expect the regular += to have the same precedence as +... -- "The workers ceased to be afraid of the bosses. It's as if they suddenly threw off their chains." -- a Soviet journalist, about the Donruss coal strike Kenneth Arromdee (UUCP: ....!jhunix!ins_akaa; BITNET: g49i0188@jhuvm; INTERNET: arromdee@crabcake.cs.jhu.edu)
karzes@mfci.UUCP (Tom Karzes) (09/19/89)
In article <2562@jhunix.HCF.JHU.EDU> ins_akaa@jhunix.UUCP (Ta06) writes:
->>A somewhat consistent but fairly bizarre syntax would be
->> x -=;
->The problem with this is that you would like it to have the same precedence
->as ++ and --. ...
-
-Why? We don't expect the regular += to have the same precedence as +...
Because all unary operators in C have the same precedence, which is higher
than the precedence of any binary or ternary operator (other than the primary
expression operators). Introducing a unary operator with lower precedence
than assignment would be a disgusting wart. Furthermore, it would make C
agonizing to parse. What would the rules be for deciding when to reduce
x-= as opposed to looking for some expression following it? Since you
naively think that binary -= should have higher precedence than unary -=,
it means that you'd always have to look beyond the -= to see if there's
something there that you can use as a second operand. So you wouldn't be
able to write x -= * 3 because this would be parsed as x -= (*3), but you
might be able to write x -= / 3 since / isn't a valid unary operator. The
whole thing it utterly absurd.
As for += not having the same precedence as +, what does that have to do with
anything? All binary assignment operators in C have the same precedence,
which is lower than the precedence of +.