in reply to Re: RFC: Junction.pm
in thread RFC: Junction.pm

Tanktalus asked above about if (all(@x) eq any(@y) {...}. I can see how useful that would be, but would have to experiment to find a way to implement it without getting as big as Q::S, while not making the code too ugly.

Actualy it is not all the difficult. Realy once you have overloaded the operators perl manages most of the extra magic to make that work without bloating your code. The code i linked to before is under 60 lines and handles that as well as embeding different any() and all() objects inside each other. For instance it handles print "YEA" if all( any(1..5), any(1..10), any(1..20)) > all(2..4); as expected.

/me is still dieing to see how you approached the problem.


___________
Eric Hodges

Replies are listed 'Best First'.
Re^3: RFC: Junction.pm
by fireartist (Chaplain) on May 03, 2005 at 17:09 UTC

    I've uploaded it to cpan as Perl6::Junction.

    It's implemented more simply than yours (plain subs / no eval), which means that it's more lines of code, but in my benchmarks ran around 500% faster.

    See my reply to Tanktalus above, for more details on what it supports.

      Actualy the speed difference has nothing to do with the evals. The evals are all done at compile time to do the overloading without 700 lines of code ;).

      The difference is that you short ccircuit the logic operation so that it stops as soon as it knows the anser. Mine collects data and reports what items caused the failure.

      A quick less than scientific benchmark using short circuiting speeds my code up to the point where yours is 350% faster still.. Which isn't bad but since the same benchmark was showing yours 1277% faster a second ago its not a bad speed up.


      ___________
      Eric Hodges

        What does the dereferencing @{} overloading do in your code? I can't see where it's being used.

        I think it'd be very nice to be able to do

        if ( all(@foo) ) {...}
        and have is evaluate the arguments for 'truth'. So I'll be adding that when I get a chance.

        I don't think I'll be adding stringification overloading. I can't really explain why, but I really don't like print any(@foo) printing a random element.

      Aren't the math operators something like:
      sub do_<op> { my ($self, $other, $switch) = @_; @$self = map { $switch ? ($other <op> $_) : ($_ <op> $other) } @$self; return $self; }

      The Perfect is the Enemy of the Good.