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

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

Replies are listed 'Best First'.
Re^5: Operator overloading with returning lists?
by ikegami (Patriarch) on Dec 02, 2008 at 14:34 UTC

    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.

      Actually if you look on CPAN there is a fork of XML::XPath done by James G. Smith as developer version. I experimented with it and it really worked for initial examples.

      Unfortunately data structures differ from XML documents in various aspects: XML elements can be repeated but not in hashes, hash keys can be as strange as you like in contrast to element names. Arrays starting with index 1 in XPath is confusing to read on data structures. And a lot of code complexity for XML that's useless on data structures: for namespaces, attributes, etc., and missing features the other way around: eg. testing for the blessed types.

      That's why I restarted it, with kind permission of James G. Smith to use his namespace.

      Not that I already have all the features, of course ...