Hacker News new | ask | show | jobs
by blindluke 2173 days ago
> Without consulting Stack Overflow, describe the “...” operator in Perl.

Poor example. Any Perl programmer can explain both range ops without breaking a sweat. Smart matching is/was the weird, misbehaving thing.

2 comments

And yet most Perl programmers I know do not work in mailing houses so they have never needed to use “...”.

I have worked with brilliant people who still have trouble figuring out the ternary operator, and people who should know better who construct ternary operators with five levels of parentheses, causing deciphering of the intent to be impossible.

So I choose Alexander the Great’s approach to solving the Gordian Knot: slice it open and remove the complexity to multiple layers that mere mortals can understand.

PS: I notice you failed to explain the operator yourself. Minus five points to Slytherin.

Indeed. That was because smart-matching in Perl was symmetric.

The smart-matching in Raku (formerly known as Perl 6) is asymmetric and customizable. If you write:

    a ~~ b
you are effectively executing:

    b.ACCEPTS(a)
In other words, the right hand side of the smart-match is responsible for accepting the left hand side. So as a developer of a class, you can add your own ACCEPTS (multi-)method to govern how your class will handle smart-matching.