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

Re: precedence of | and &



In article <brucehoult-1503001808330001@bruce.bgh>, brucehoult@pobox.com
(Bruce Hoult) wrote:

> The folly of relying on precedence in complicated expressions aside, does
> anyone else think that it would really be better if | had lower precedence
> than &, as in practicaly every other language in common use?

I just checked the Gwydion source-base.

Grepping for the pattern "\|[^;]*&|&[^;]*\|" finds 126 matches (caution --
don't use grep/egrep as it doesn't search across line boundaries -- I used
BBEdit on a Mac, but Perl should work too) where | and & are both used
without a ; between them and examining those matches by hand found only
one (1) place where the precedence of & and | is in fact assumed by the
code...

/src/tools/melange/c-decl.dylan, line 510:

define method find-slot
    (decl :: <structured-type-declaration>, name :: <string>) 
 => (result :: <declaration>);
  decl.members
    & any?(method (member) member.simple-name = name & member end method,
      decl.members)
    | error("No such slot: %s", name);
end method find-slot;

Every other case was either a false-positive or else parentheses were used
to disambiguate the code.

Notes that this code appears to assume left-associativity (as per the DRM)
and so wouldn't have been working properly under the d2c bug fixed today
(it would silently fail if decl.members was not initialised instead of
reporting "No such slot").


Do the Functional Objects people have any idea of the likely impact of a
change on their existing code?

-- Bruce



References: