[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: LPeg and Lua 5.3 operators**
**From**: Sean Conner <sean@...>
**Date**: Wed, 14 May 2014 22:33:40 -0400

It was thus said that the Great Tom N Harris once stated:
> On Wednesday, May 14, 2014 05:24:10 PM Coroutines wrote:
> > I know * was chosen for "concatenating patterns" because it closer
> > resembles the dot operator, but imo it'd make sense to use + for that.
>
> __mul was chosen because of the precedence. Concatenation should have a higher
> precedence than ordered choice. So a number pattern would look like:
There's also precedence in Boolean algebra. The following:
AB+C
can be read as:
A * B + c
or
A and B or C
Also, note that
A * 1 = A
A + 0 = A
and in Boolean algebra:
A and 1 = A
A or 0 = A
So, it makes some sense to use * for concatenating patters because you can
read:
A * B
as
pattern A AND pattern B must match
and
A + B
as
pattern A OR pattern B must match.
-spc