Ben Morrow wrote: > Quoth demerphq@gmail.com (demerphq): >> On 2 August 2010 00:54, karl williamson <public@khwilliamson.com> wrote: >>> I think I like your idea. �Let me make sure I understand. �A tilde >>> immediately following '(?' means that the clustering group is to have the >>> default modifiers, subject to any flags that come after it. �Thus (?~:abc) >>> means all default flags. �(?~x:abc) means the defaults except use the x >>> modifier, and (?~-x:abc) means the defaults without the x modifier, which is >>> a somewhat more complicated way of writing the equivalent (?~:abc). >>> >>> regex stringification could change to output just the non-defaults, or we >>> could leave them as-is, and just add the tilde. �Since we would already be >>> breaking compatibility, I would think we might as well remove them. >>> >>> A tilde is not the ideal choice because it can easily be confused with a >>> minus sign. �I don't know if there are other characters that could be used >>> instead. >> Can you paint a picture for me as to how you think this is useful and >> would work in practice? What problem it solves? >> >> Right now I would vote against this idea in terms of minimal benefit >> for long term costs, so maybe I don't understand the point properly. > > You may be right. > >> Top of my mind questions: >> >> How do you define "the default modifiers"? Assume we have them, and >> they end up user configurable, what happens when a regex is compiled >> in one context and the interpolated in another? > > They can't be user-configurable, at least not as far as (?~:) is > concerned. If there is some pragma that sets a 'default' set of > modifiers, then (?~:) must always be with respect to the 'default > default'. > >> What is the difference between /(?~i:foo)/ and /(?i)foo/ > > Nothing. However, > > "FOO" !~ /(?~s:foo)/i > > but [ as amended] > > "FOO" =~ /(?s)foo/i > > of course. The two existing syntaxes both inherit any unspecified > modifiers from the outside, which is what we're trying to avoid. > > Ben > I think either an underscore or a period would be better than the tilde, so will use an underscore in my examples. (?_:foo) would mean that the flags that are the compiled-in Perl defaults are operative for the duration of the cluster. (?_x-s:foo) means use the compiled-in defaults, except specify the x flag. The '-s' is a no-op because it is already a compiled-in default. Without the '_', the cluster inherits the surrounding flags. Allowing the user to change their defaults has no negative consequences. The problem that this solves is that if we ever add more flags again, and I can think of several possibilities, we don't have to alter tests or modules that don't use those flags but are expecting a certain stringification. I think it's worth it to bite the bullet now, where everyone agrees we need to add some flags that have to be there, and change to use this scheme. Then when we add those other flags, we won't affect existing tests and code. I personally don't think I would ever write code that would require a certain stringification, even under deadline, but those that did will of necessity be affected by whatever we decide here. But then, they won't be affected by our future decisions, unless they are passed regexps that have non-defaults of the new modifiers. We can't help them there.Thread Previous | Thread Next