On 16 Feb 2003, Michel Arboi wrote:
> _Currently_, things like ! x == y are parsed as (!x) == y, which is
> wrong IMHO. It should be ! (x == y)
> Worse "! x >< y" is parsed as "(!x) >< y" which is absurd.
> So, the priority of NOT should be set _below_ the priority of the
> compare operators.
This makes some sense because ! is supposed to negate a logical formula
like x == y, not a term like x, y (in the first-order logic). I bet you
can find some textbooks where "x is not equal to y" is written as !x==y
(of course, they use a "hook" instead of !, and = instead of ==).
On the other hand, I am sure you can find even more textbooks where the
same things is always written as "!(x==y)". I doubt the authors of the
latter books decided to write it that way under the influence of any
programming language...
Personally, I find a syntax with an unary operator (esp. a short one)
having lower precedence than a binary operator highly confusing.
> Where exactly? Below AND and OR? Or not?
> i.e. "! x && y" = "! (x && y)" or "(!x) && y" ?
> I vote for the 2nd interpretation.
The logical negation has always had higher priority than binary logical
connectives.
On 16 Feb 2003, Michel Arboi wrote:
> * I cannot see why "x == y == z" or " x < y < z" is authorized in C
> or Perl. If somebody needs it, it should be implemented the way it
> is in mathematics (i.e. "x < y and y < z" and not some crazy
> integer to boolean compare)
These languages have no dedicated boolean type and no dedicated operators
for logical equivalence and implication. When you need them, you have to
use the integer equality for equivalence (obvious) or the right integer
inequality for implication (much less obvious, perhaps even counter-
intiutive, because A ---> B has to be written as A <= B...of course, you
can always use !A || B...). This might explain why things like (x == y)
== z or (x < y) < z (parentheses are intentional) are allowed.
Why they made relational and equality operators associative is beyond
me. Perhaps they intended to give just another proof these languages
provide anyone enough rope to hang himself? :)
> * And I am just realizing that we should forbid things like "!!x" or
> "~~ x" because they are useless now and may clash with some future
~~x (i.e. bitwise negation of bitwise negation) is pointless because the
result is the identity. !!x is not the same as x in C--it is a funny
shortcut for x != 0 (which is a shortcut for x != 0 ? 1 : 0). (Also,
those two things are not the same in intuitionistic logic...but I suppose
such a formal logic finesse is irrelevant for the design of a simple
imperativeprograming language...)
> operator (Sorry Renaud! Implementing "!!" is easier than the fish
> operator ">(°>" :)
Do not forget the Broccoli operator ("<>")! :)
> Anyway I agree that one expects a "compact" operator (I mean, with a
> very short name) like "!" to be strongly tied to the next variable.
> That's more a problem of readability than logic.
Yes. (See above.)
--Pavel Kankovsky aka Peak [ Boycott Microsoft--
http://www.vcnet.com/bms ]
"Resistance is futile. Open your source code and prepare for assimilation."