Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^3: RFC:

by fireartist (Chaplain)
on May 03, 2005 at 17:09 UTC ( #453687=note: print w/replies, xml ) Need Help??

in reply to Re^2: RFC:
in thread RFC:

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.

Replies are listed 'Best First'.
Re^4: RFC:
by eric256 (Parson) on May 03, 2005 at 20:19 UTC

    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.

        The @{} lets you do my $large = any(1..10) > 5;my @large = @{$large}; That is why I don't short circuit. The stringification is something i went back and forth on. It might fit better as any(1..10)->string; but I dunno.

        BTW I added in the arthimitic. The nice thing about the dynamic way I overload is that it was only a few extra lines of code.

        my $mix = all(1..5) + any(1,2); produces a result like my $mix = all(any(2,3),any(3,4), any(4,5),any(5,6), any(6,7));

        Operator overloading realy is magic. ;) I also added a regex ->match method which alls things like if (any(@strings)->match(all($regex))

Re^4: RFC:
by dragonchild (Archbishop) on May 03, 2005 at 17:27 UTC
    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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2021-01-25 00:41 GMT
Find Nodes?
    Voting Booth?