Cross posted from my blog

Welcome to Perl 5 Porters Weekly, a summary of the email traffic on the perl5-porters email list. The smartmatch discussion continues to be very popular, so its summary will go at the end of this post. There was also a very long, very tedious thread about how Perl ought to handle UTF-8 output which almost demonstrated [Godwin's Law] [1] (the longer a thread continues, the higher the liklihood someone will call someone else a Nazi.)

If you're reading this on my blog or somewhere else on the web, you can now find the summaries in Markdown format in [this github repository] [2].

Also, since there seems to be influx of new readers, ohai! I started writing these summaries after YAPC::NA 2012 after having a breakfast conversation with Gabor Szabo. If you don't already read his Perl Weekly email newsletter, you really ought to sign up for it.

Topics this week include:

  • Term::ReadLine::Perl not moving forward
  • DTrace probes for loading-file, loaded-file, op-entry
  • My Perl Foundation Grant for Improving the Perl Debugger Was Accepted
  • utf8 problems (still, )
  • fixing smartmatch (again (still))

Term::ReadLine::Perl not moving forward

Rocky Bernstein posted a note that his patch to modernise parts of Term::ReadLine::Perl haven't been acknowleged yet. The patch add GNU Readline's ReadHistory, WriteHistory, and StifleHistory. PAUSE admin Steffen Mueller suggested Rocky try to acquire comaintainer status for this distribution.

Read the thread

DTrace probes for loading-file, loaded-file, op-entry

Shawn Moore (aka Sartak) submitted a patch to extend DTrace coverage to loading-file, loading-file during require, use, and do, and another patch traces each opcode excution. DTrace is an amazing tool to have in your toolbox and it's great to see this work get merged in blead. While DTrace is usually considered a Solaris technology, it's also available in FreeBSD and Mac OS X, so if it's available on your platform, it's worth learning. An easy way to get started with DTrace and Perl is to check out the perldtrace docs Perl ships.

Read the message

Read perldtrace

My Perl Foundation Grant for Improving the Perl Debugger Was Accepted

Shlomi Fish wrote that his grant proposal to improve the perl debugger was accepted by the Perl Foundation. Later there was some back and forth from Rocky Bernstein and Shlomi about incorporating some of the work that Rocky is doing with his own debugger tools called Devel::Trepan.

Read the thread

utf problems (still, )

Linda W reported that a UTF-8 character in her Perl source was rendered incorrectly in a debug session. She proposed that in some future version of Perl 5.x STDOUT get a default encoding layer. The thread then proceeded for about 30+ messages with various people attempting to explain what was happening and why Perl STDOUT won't get a default encoding layer. Ricardo finally posted

Nobody really minds explaining why stupid things are stuck being stupid.
It's very tiring to see you repeatedly harangue the very people who try 
to give an explanation.

[...]

Please stop calling people trolls, despots, or deluded.  It doesn't 
accomplish anything but make the idea of trying to respond to your 
reports less palatable.

I thought that might end the thread but like a shambling zombie, it just keeps going. Normally, I'd ignore a thread like this, but it was up over 50 replies in the course of the week. That's 45 minutes of my life I'll never get back and now it's 20 seconds of yours. Mazel tov!

fixing smartmatch (again (still))

Last week I promised I'd detail Ricardo's response to a proposal to deprecate smartmatch and wrap a thin layer of syntactic sugar around the when construct. Here's what he wrote (sorry, there's no tl;dr version, it's already pretty dense):

## The New ~~ Operator

$a      $b                  Meaning
======= =======             ======================
Any     undef               ! defined $a
Any     ~~-overloaded       ~~ overloading is used
Any     Regexp, qr-ol       $a =~ $b
Any     CodeRef, &{}-ol     $b->($a)
Any     Any                 fatal

So, this is the table I proposed in July 2011, and it's what I think 
we're back to.  No special cases.

There is no question of how ($x=5) somehow became ambiguous, because 
if $x contains 5 or "5" is is not allowed as the smartmatcher operator, 
period.  Use Smart::Match and say stringwise(5) or numwise(5), or 
pass sub{$_==5}

If both 'qr' and '&{}' are overloaded, '~~' must be overloaded to 
disambiguate.

Switches are still okay.

## The new behavior of given/when

given ($x) {
    when ($y)  { ... } # $x ~~ $y
    when (4)   { ... } # $x == 4
    when ('4') { ... } # $x eq 4
}

Deferred/computed values of any sort mean smart match.

Two dead-simple special cases: Numeric literals mean ==.  String literals 
mean eq.

If you want one case for $x eq a or b or c, then:

given ($x) {
    when (stringwise any qw(a b c)) { ... }
}

## What about what Father C. said?

Sprout proposed that smartmarch be jettisoned and that `when` always 
evaluate its parameter as a boolean expression, save for the same simple 
cases above.

For the "$x eq a or b or c" example, that gives us at least two simple 
choices:

given ($x) {
    # Here, "any" returns a "junction" that distributes the eq
    when ($_ eq any qw(a b c)) { ... }
}

Or:

given ($x) {
    # Here, stringwise implies the "$_ eq"
    when (stringwise any qw(a b c)) { ... }
}

My thoughts on this are:

* I like the idea that we can have matcher objects that can be passed 
in more succinctly than a sub.  ->set_matcher(qr/../) or 
->set_matcher($obj) both seems simpler to me than 
->set_matcher(sub { /.../ }) or ->set_matcher(sub { $obj->match($_) })

* If we do, then Smart::Match and many other things keep working as 
they have without needing to be rewritten.  This is nice.

As Father Chrysostomos suggests, perl does not *need* smartmatch.  
Really, it doesn't need need features.  My question is, does perl 
benefit more from this fix to smartmatching than it does from simply 
removing it?  I believe it does.

Most people seem to be satisfied with this response. Rik later expanded on some code examples in another message:

The exhaustive set of "when" behaviors would be:

given ($input) {
    when (1)   { ... } # if $input == 1
    when ('x') { ... } # if $input eq 'x'
    when ($x)  { ... } # if $input ~~ $x
}

And further demonstrated:

given ($input) {
    when (undef)  { ... } # if $input ~~ undef
    when ($x + 2) { ... } # if $input ~~ ($x + 2)
    when ($_ > 1) { ... } # if $input ~~ ($_ > 1)
}

Under FC's proposal, which would eliminate ~~ entirely:

given ($input) {
    when (1)   { ... } # if $input == 1
    when ('x') { ... } # if $input eq 'x'
    when ($x)  { ... } # if $x
    when (undef)  { ... } # if undef
    when ($x + 2) { ... } # if ($x+2)
    when ($_ > 1) { ... } # if ($_ > 1)
}

And the smartmatch discussions carry over into September. See you next week.

Read the thread

Leave a comment

About Perl 5 Porters Summaries

user-pic Weekly p5p summaries