Rick DeNatale wrote:
No, the only difference between && and ‘and’ is their parsing precedence.
And nearly every time I’ve seen and used instead of && I’ve found a bug.
I use it sometimes for control flow in DSL-ish situations. Here’s a
line from a toy recursive descent parser:
@sign *= -1 if lookahead == '-' and consume
Here, I use
and specifically as a way to denote control flow. I
agree that encountering a line like this somewhere in the middle of a
generic codebase is very surprising and often puzzling, but in this
case it is a highly stylized codebase with its own idioms.
For example, that same parser also contains the line
while parse_digit; end
or this one
parse_string or parse_array
Again, I would never write something like this in generic code, but
in this particular case it is my specific idiom to encode the EBNF
string | digit
This allows me to distinguish between infrastructure code that is
there to support the parser, and the actual parsing rules themselves,
since the former always uses parentheses,
! and the
latter always uses
not and doesn’t use parentheses.