in reply to Operator overloading with returning lists?

Contextual::Return should help you! AFAIS the principle of returning an object which transforms later (to a list in your case) seems to be the same like in the already mentioned Quantum::Superpositions

Cheers Rolf

UPDATES:
+ fixed links.
+ after a quick look at Quantum::Superpositions I think Contextual::Return fits much better into your needs.
+ PS: If this works, I'd be glad to get feedback about it 8 )

  • Comment on Re: Operator overloading with returning lists?

Replies are listed 'Best First'.
Re^2: Operator overloading with returning lists?
by renormalist (Sexton) on Nov 30, 2008 at 13:19 UTC

    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.

      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