in reply to Re: Operator overloading with returning lists?
in thread Operator overloading with returning lists?

Thanks for all your answers. Contextual::Return was a very nice idea. Unfortunately it did not work for the operator. Although C::Return allows more precise detection than the normal wantarray it's still the wrong context in which the expression is evaluated, so I could not get to to use in anything else than SCALAR.

I heard that '~~' should slightly change its semantics in 5.10.1, maybe it would be possible to even more enhance it with context awareness, e.g. in order to harmonize it with the Perl6 operator (do those allow context detection?). I should now ask in p5p ...

Thanks again.

  • Comment on Re^2: Operator overloading with returning lists?

Replies are listed 'Best First'.
Re^3: Operator overloading with returning lists?
by LanX (Saint) on Nov 30, 2008 at 17:43 UTC
    I don't understand exactly what you your aim is. Could you give us more use cases? The LHS is a scalar or is it an array/list???

    Cheers Rolf

      I have a sublanguage called "DPath" (inspired by XPath) which is used like this:
      $data = ...# some Perl data structure @resultlist = dpath('/AAA/BBB/*/CCC')->match($data);
      In @resultlist are all elements of $data which match the path '/AAA/BBB/*/CCC'. Due to its "matching nature" this could imho look more naturally when expressed with an overloaded '~~' (and maybe some prototype "dpath($)"), like this:
      $data = ...# some Perl data structure @resultlist = $data ~~ dpath '/AAA/BBB/*/CCC';

      That's what I want to do.

      The dpath() function returns an object of a class to which I hoped to bind the overloading.

      Thanks,
      Steffen

        I have a sublanguage called "DPath" (inspired by XPath)

        Interesting. I wonder why XPath wasn't used? All the examples in the Synopsis are also valid and equivalent XPaths. It's not all that much work either, since XML::XPathEngine can be used to add XPath support to any tree class.