lua-users home
lua-l archive

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


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