[RCR] Global Regexp Match Mechanism (//g)

Why should the String keep track of the “pos” if the string has been mutated? In the code that I am trying to convert, if the string is modified, the code itself is responsible for resetting the \G position. IMO, the functions which prepend should invalidate the matchpos (e.g., nil).

-a

···


austin ziegler
Sent from my Treo

Hi,

···

At Sat, 14 Dec 2002 02:46:23 +0900, Austin Ziegler wrote:

Why should the String keep track of the “pos” if the string
has been mutated? In the code that I am trying to convert, if
the string is modified, the code itself is responsible for
resetting the \G position. IMO, the functions which prepend
should invalidate the matchpos (e.g., nil).

The costs are almost same, and feel expensive to me. Even if
not, I can’t agree it because of the thread unsafeness.


Nobu Nakada

“Austin Ziegler” austin@halostatue.ca writes:

Why should the String keep track of the “pos” if the string has been
mutated? In the code that I am trying to convert, if the string is
modified, the code itself is responsible for resetting the \G
position. IMO, the functions which prepend should invalidate the
matchpos (e.g., nil).

That’s a solution, though as Nobu Nakada pointed out the whole idea of
having the String keep track of “pos” at all is flawed – since it is
not thread safe.

Also, String#index and an extended Regexp#match that takes an index
allow the user to manage “pos” themselves in however they see fit.

Hi,

···

At Sat, 14 Dec 2002 05:27:29 +0900, Matt Armstrong wrote:

Why should the String keep track of the “pos” if the string has been
mutated? In the code that I am trying to convert, if the string is
modified, the code itself is responsible for resetting the \G
position. IMO, the functions which prepend should invalidate the
matchpos (e.g., nil).

That’s a solution, though as Nobu Nakada pointed out the whole idea of
having the String keep track of “pos” at all is flawed – since it is
not thread safe.

Furthermore, it doesn’t seem to be appropriate to String as
written in [ruby-talk:58952], IMO. “pos” function in Perl is a
workaround to specify position with matching operator, whereas
the operator is also a method in Ruby, there’s no reason to
avoid an explicit method.


Nobu Nakada