At 9:08 AM -0800 3/9/05, Larry Wall wrote:
My other quibble is that you seem to be prone to stating things in the
negative for at least two of your three tests here:

    subtype KeyName of Str where { $_.defined and $_ ne '' and $_ !~ m/\W/ }

and it seems to me that you could simplify all that to just

    subtype KeyName of Str where { m/^\w+$/ }

If that succeeds, you know it's defined and non-null.  You might argue that
the m/\W/ short-circuits, but I would counter-argue that failure is
supposed to be the exceptional case, and in every successful call you have
to scan the whole string anyway.  Plus it's just easier to understand.
And it lets you write the constraint without explicit reference to $_,
which I will admit was my first motivation in wanting to rewrite your
constraint.  The negatives and redundancies I only noticed later.

Okay, I have gone and replaced the "$_ ne '' and $_ !~ m/\W/" with a "m/^\w+$/".


However, unless Perl 6 is different than Perl 5 in its treatment of undefined values, I still need the ".defined" part, meaning I end up with:

  subtype KeyName of Str where { .defined and m/^\w+$/ }

In Perl 5, running something like the un-gated "$msg_key =~ m/^\w+$/" gives this warning:

Use of uninitialized value in pattern match (m//) at Locale/KeyedText.pm line 85.

To avoid that, I do "defined( $msg_key ) and $msg_key =~ m/^\w+$/" in Perl 5.

You have mentioned before that Perl 6 still treats the use of undefined values other than in boolean context as an error. So would applying a Rule against an undefined value produce a warning in Perl 6 or not? (A quick scan of S12 didn't say.)

-- Darren Duncan

Reply via email to