Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: RFC: Junction.pm

by Tanktalus (Canon)
on May 02, 2005 at 14:40 UTC ( [id://453266]=note: print w/replies, xml ) Need Help??


in reply to RFC: Junction.pm

Just out of curiosity...

if (all(5, 10, 15) > any (3, 8, 12, 20)) { print "Success!\n" }
Does that work? :-) Also, I'm not sure if you can override =~, but that makes much more sense in perl5 land than allowing a regex or something as a parameter, as long as you're going about all this syntactical sugar anyway:
if (all(@input) =~ /^\d+$/) { print "Got all whole numbers!\n" }
looks much better than:
if (all(qr/^\d+$/, @input)) { ... }
Also, these don't make a lot of sense (to me, anyway) in OO format (and I'm an OO freak!). I'd expect more like:
use Junction qw(any all); if (any(@list) > 0) { print "we have at least one postive number!\n"; +} if (all(@list) > 0) { print "even better - they're all positive number +s!\n"; }
I'm not sure why you need that object anyway.

Replies are listed 'Best First'.
Re^2: RFC: Junction.pm
by fireartist (Chaplain) on May 02, 2005 at 15:01 UTC

    Agreed, exporting the subs makes a lot more sense. I originally had only the object interface, because of the way it was built - it should have occured to me to use Exporter once that was no longer needed.

    if (all(5, 10, 15) > any (3, 8, 12, 20)) { print "Success!\n" }

    No, that doesn't work. I could make it work, but then it's starting to get into the complexity of Quantum::Superpositions (which I've still to fully read the docs of).

    Unfortunately, =~ can't be over-riden: that would be very nice. (And why Damian hasn't released Perl6::SmartMatch, I don't know ;)

Re^2: RFC: Junction.pm
by fireartist (Chaplain) on May 03, 2005 at 17:03 UTC
    if (all(5, 10, 15) > any (3, 8, 12, 20)) { print "Success!\n" }

    Yes, it does work!
    I should have tested before I answered: I realised that of course it would work, as the operators the module used are still overloaded, even when being used inside the module.

    if (qr/^\d+$/ == all(@input)) { ... }

    The above now works. Note that you need to use a regex object qr// rather than just //, and you also need to use '==' or '!=', not '=~' or '!~'. It isn't ideal, but then you only need to use it if you want to!

    btw, I've uploaded this to CPAN as Perl6::Junction.

    update: changed the above link, as the cpan indexer hasn't picked it up yet, when you search by module name.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://453266]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-19 04:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found