develooper Front page | perl.perl5.porters | Postings from August 2010

Re: Any opposition still to the idea of syntax indicating defaultregex modifiers?

Thread Previous | Thread Next
From:
karl williamson
Date:
August 15, 2010 12:13
Subject:
Re: Any opposition still to the idea of syntax indicating defaultregex modifiers?
Message ID:
4C683C2F.80706@khwilliamson.com
Ben Morrow wrote:
> Quoth public@khwilliamson.com (karl williamson):
>> Ronald J Kimball wrote:
>>> On Sat, Aug 14, 2010 at 09:13:06AM +0100, Zefram wrote:
>>>> Ronald J Kimball wrote:
>>>>> my @options_on  = qw/ s a /;  # where a and b are hypothetical options
>>>>> my @options_off = qw/ i b /;  # that are on by default
>>>> No options are on by default.
>>> I know that's the current state, but is that a guarantee going forwards?
>>> If options will always be off by default, then we probably don't need
>>> (?.m-i:) at all; (?.m) would be sufficient.  (And my objection to Ben's
>>> proposal would be moot. :)
>>>
>>> I note that Karl mentioned that the new regex modifiers - /l, /u, and /d -
>>> are "automatically inserted" under the appropriate conditions.  I don't
>>> know if that means they are "on by default" with regards to (?.)
>>>
>>> Ronald
>>>
>> Yes, /d is on by default.
> 
> But there is never a need to turn it off explicitly: it's not a boolean
> option, but a three-way choice. The way to turn it off is (?.l:foo) or
> (?.u:foo), not (?.-d:foo).

More than one person has expressed a preference for ^ over dot, so I'm 
thinking that will be what it ends up being.
> 
> I've mentioned in passing before, and I think I should say again, that
> having a /d switch at all is rather confusing. IMHO it would be much
> better (if we're going to restrict ourselves to one-letter switches with
> no arguments) to just have /u and /l, with the old behaviour implied by
> neither of those being present. The new (?.:) syntax would mean that the
> one place where /d might potentially be used, (?d-xims:foo), is better
> written (?.:foo).
> 

I mostly agree, except if that is the one flag that is being switched, 
you don't want to have to specify all of them.  I don't understand why 
the /d is confusing.  These operate like radio buttons; my 12 year old 
car still has them.  don't know about newer cars.  The radio is always 
tuned to a station.  You press the button of the station you want.

> If you're going to introduce pragmata to turn some switches on for some
> lexical scopes, the question of 'so how do they get turned off again?'
> needs to be addressed in a more systematic way than just introducing a
> single special-case switch that turns some other switches off. I would
> be happy with either of
> 
>     use unicode_strings;
>     /foo/U;
> 
> or
> 
>     use unicode_strings;
>     /foo/-u;
> 
> though the latter obviously has more back-compat considerations. I would
> also be happy, for now, with requiring people write
> 
>     use unicode_strings;
>     /(?-u)foo/;
> 
> if they want to go back to the old semantics.

I would find this confusing.  Either of your examples says what the 
person  doesn't want.  It doesn't say which of the other (currently two) 
choices they do want.  You can't unpress a radio button to go to another 
station; you must press the button you want.  As more possible things 
like /a got added, it would get worse.
> 
> While we're discussing this: would you be at all open to the idea of
> supplying a /a ('ASCII') switch that makes \d\s\w match what everyone
> thinks they do (that is, [0-9], [ \t\n] and [a-zA-Z0-9_] respectively)?

I think that if we're going to discuss this now, it should go on another 
thread.  It has been discussed before, and is a possibility, but I think 
it's part of a larger problem, and I think would be better served by a 
more general 'use script pragma' that allows ASCII as a special 
sub-script of Latin.
> 
> Ben
> 


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About