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

Featurewish: Context aware operator overloading

Thread Next
From:
Steffen Schwigon
Date:
May 25, 2010 06:36
Subject:
Featurewish: Context aware operator overloading
Message ID:
87sk5g5ciq.fsf@renormalist.net
Hi!

Forgive me this passive way of just wishing a feature. I can't provide
more than a user's perspective. Anyway:

Would it make sense to make operator overloading context aware?

Currently an overloaded operator only runs in scalar
context. Therefore I do nasty dereferencing like

  my @list = @{ $data ~~ dpath '//affe/zomtec' };

just because the overloaded '~~' cannot return an array.

What I would want is

  my @list = $data ~~ dpath '//affe/zomtec';
  my $head = $data ~~ dpath '//affe/zomtec';

with the sub behind the overloaded '~~' doing the usual wantarray
drill.

I have, however, no more knowledge about this, except that someone
once said the original author of overloading hadn't found it
neccessary, IIRC.

And yes, I know that this would probably introduce trouble on
backwards compat. Maybe it can be protected by some “use feature”
magic.

Thanks for listening.

Kind regards,
Steffen 
-- 
Steffen Schwigon <ss5@renormalist.net>
Dresden Perl Mongers <http://dresden-pm.org/>

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