The elegant dividend that Perl derives from its lack of operator ambiguity
Hm. If only that notion had been carried through to other operators like the bitwise boolean operators where it is all to frequent that you need to enforce the context by explicit coercions.
Not a big criticism, but it still catches me out occasionally.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
| [reply] |
Fully agreed. Other places where the context model has not been applied consistently:
- The reverse operator does either string or list reversal depending on the calling context. Doesn't fit the pattern.
- infix x does either string or list repetition, not by imposing context or by being sensitive to the outer context, but by introspecting the left-hand side. WRONG.
Perl 6 has addressed those points, thought it took quite some time for some of them.
| [reply] [d/l] |
Just read S03: Changes to Perl operators. Impressive consistency improvements. I like the new x (string multiply) versus xx (list multiply) distinction.
I suppose the vast number of operators that Perl supports, compared to other languages, is made possible by sigils; that is, languages without sigils couldn't so easily use x or xx as an operator. BTW, I was surprised to learn that the string multiply operator is commutative in Python (that is, "X"*3 and 3*"X" both produce "XXX"), which looks a bit odd to me (you learn these things playing golf you see ;-).
I also revisited the lovingly crafted Periodic Table of the Operators -- which clarifies why Perl is sometimes referred to as an "operator-oriented language".
| [reply] [d/l] [select] |
| [reply] |
such as the smartmatch operator.
I've never used that in real code. Nor given/when for that matter.
I've tried to use both a few times for the sake of using them, and found that the reality didn't fit with my expectations, to the point where even reading the documentation over and over, I couldn't work out why I got the results I did. As such, neither have ever made it into my working vocabulary, despite that I know they are there.
Extending Perl requires far more than just implementing a few specific behaviours. It seems to me that you really need Mr Wall's particular brain -- and considerable time -- to see the full impact of such changes.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
| [reply] |
The elegant dividend that Perl derives from its lack of operator ambiguity
Really? Can you describe what &, |, ++ and <> do, without taking the value of their operands into account?
Yes, overloading + to mean either string concatenation or numeric addition is a language design blunder IMHO. I'm often saddened by how many language designers were seduced by this unfortunate misfeature.
I don't call it a misfeature. It's a design decision whether you allow multiple dispatch or not. There are pro and cons, and judgement should be made in context of the entire language. If your typing system is different, multiple dispatch makes more sense (perl6 will have multiple dispatch, although I don't know whether it will have it for build in operators). Perl5 doesn't have much of it, but do note the mentioned operators. And it allows operators to be overloaded. If I want to make + to concatenate strings, I can, quite simply:
use 5.010;
use overload '""' => sub {${$_[0]}},
'+' => sub {bless\do{my$o=${$_[$_[2]]}.$_[1-$_[2]]}};
BEGIN {overload::constant q => sub {bless \do {my $v = $_[0]}}}
my $x = "Hello";
my $y = "world";
my $z = "" + uc $x;
say $x + ", " + $y;
say $z + $z;
__END__
Hello, world
HELLOHELLO
(Implementation not complete) | [reply] [d/l] [select] |