in reply to Re: Returning a Junction
in thread Returning a Junction

++fletcher_the_dog

Only problem is that, while my example above used the any() style junction, there is also the all() type (i.e., all elements in the junction must match).

Probably the best way around this is to split into two packages: junction_any and junction_all. The implementation for compare under junction_all would be something like this:

sub compare { my $self = shift; my $string = shift; foreach my $key (keys %{ $self }) { return 0 if $string ne $key; } return 1; }

For completeness, you'll want to provide equivilent overloading for the other comparison operators, too.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Re: Returning a Junction
by fletcher_the_dog (Friar) on Sep 04, 2003 at 19:40 UTC
    I don't know a lot about junctions, but it seems to me in order for a string to ever pass an all_junction compare there could only be one key in the junction. i.e. "Visa" only matches "Visa" in a string compare, if there is anything else the compare will fail. An all junction I would think would only work if you were comparing two junctions.
      And, in fact, it is the logical default for comparing junctions. It's basic set theory. Two sets are equivalent if they contain the same elements. What junctions do need is to see if one junction is a subset of another junction. This is equivalent to asking if every $foo in junction $bar is within the other junction $baz.

      ------
      We are the carpenters and bricklayers of the Information Age.

      The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.