[Prev][Next][Index][Thread]

Re: precedence of | and &



In article <brucehoult-1503001808330001@bruce.bgh>,
Bruce Hoult <brucehoult@pobox.com> wrote:
>I also wonder about the associativity.  Andreas just fixed a bug in d2c
>where | and & were right-associative when the DRM says they should be
>left-associative.
>
>In a chained expression such as...
>
>   a | b | c | d
>or
>   a & b & c & d
>
>... it makes no difference to the actual answer (well, unless I'm getting
>really confused...) whether the operators are left-associative or
>right-associative.  It seems to me that right-associative ...
>
>a | (b | (c | d))
>a & (b & (c & d))
>
>... seem more natural because it implies that the exit occurs as soon as
>it can.  If it was left-associative ...
>
>((a | b) | c) | d
>((a & b) & c) & d
>
>... then it appears as if all the operators have to be evaluated even
>though the result is the same.

Since the semantics are the same either way, I think it makes sense for
their associativity to be the same as other operators in the language, to
avoid having another special case.

-- 
Barry Margolin, barmar@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



References: