lua-users home
lua-l archive

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



> I would like to suggest the addition of a new pattern item which will
> behave just the like the %bxy one but will return the match without
> the xy part.
...
> Does anyone else see any merit (or problem, other than the usual
> minimalism objections) in this proposal?

Every pattern can be looked at in two ways.

Yang:  What does it provide under gmatch?
Yin: What does it leave behind under gsub?

Let's say your pattern will be called %B. The first question to ask is:
"Is there anything %B can do that %b cannot do, or vice versa?"
and one must look at it from both perspectives.

Under Yang it is a tie. It is just as easy to re-concatenate the delimiters
to the result of %B as it is to :sub them away from the result of %b.

Under Yin %b wins. It is easy to put two delimeters back in but you will
need to repeat the whole exercise in order to take empty balanced pairs
of them out.

I.e. if we have only one of %b and %B, then it must be %b.


I disagree.
I'd prefer %B to be implemented instead of %b.

Delimiters are hardcoded into pattern and thus delimiters in the result string
do not carry any useful information.
Delimiters are usually part of the container, not part of the payload.

In real life you are usually throwing away all packing materials
of all the thing you have bought, isn't it?

In your reasoning about Yang and Yin you implicitly assume that
both options (whether result should include delimiters or not) have
equal chances to be useful for user.
You have completely forgotten that in most situations in practice
you are spending your time to clear those delimiters away from the result.