Newsgroups: rec.arts.int-fiction
Path: news.duke.edu!newsgate.duke.edu!nntp-out.monmouth.com!newspeer.monmouth.com!feeder.qis.net!nntp.abs.net!uunet!dca.uu.net!ash.uu.net!world!buzzard
From: buzzard@world.std.com (Sean T Barrett)
Subject: [Inform] precedence of ~~
Message-ID: <GH7JGw.1FM@world.std.com>
Date: Sat, 28 Jul 2001 23:48:32 GMT
Organization: The World Public Access UNIX, Brookline, MA
Lines: 44
Xref: news.duke.edu rec.arts.int-fiction:90333

According to DM4, ~~ has the same precedence as && and ||.
I'm not sure what that's supposed to mean, since one is a
unary prefix operator and the others are binary operators.

The binary operators have an explicit grouping rule for
tiebreaking--"left associative", so "w && x || y && z"
will always mean "(((w && x) || y) && z)" but there's no
such rule for ~~.

So the question is, what SHOULD it mean to say

    (~~x || y)

I'd expected this to behave like C where not ("!") has
much higher precedence (all unary operators are high
precedence in C); even though in Inform, ~~ and || have
the same precedence, it seems plausible that the left
associativity would imply the ~~ would group before
the ||, and it would act like ((~~x) || (y)). This would
also be symmetric with the interpetation of "(x || ~~y)",
whose grouping is unambiguous.

However, in practice it actually behaves like

    (~~(x || y))

which I'm pretty sure amounts to saying that it's
lower precedence than || and &&.  By that logic, either
DM4 or Inform has a bug; my personal preference is to
blame it on the Inform compiler in this case, although
really I think you can't really claim a unary operator
has equal precedence to a binary operator--it either binds
more or less tightly. (The unary operator can never conflict
with the binary operators to its left, so the issue is
what happens with the first binary operator on its right,
so there's no need to introduce a "left-associative" or
"right-associative" sort of rule.)

Comments?

(I bring this up because it took me far too long to
find a bug which turned out to be due to this.)

SeanB
