Has anyone found a useful use for Quantum::Superpositions? I'm not talking about a computing breakthrough or anything silly like that (which is impossible for obvious reasons), but just a use for it which provides a more elegant solution than current functionality allows. Anyone?

Neat module, excellent use of Class::Multimethods too. Check it out if you haven't already.

  • Comment on Useful uses of Quantum::Superpositions?

Replies are listed 'Best First'.
Re: Useful uses of Quantum::Superpositions?
by diotalevi (Canon) on Apr 04, 2003 at 06:57 UTC

    Well sure - who couldn't use the any() and all() functions? They're so useful that perl6 included them in the core. The idea is that you can say something like 5 == any( 1 .. 10 ) and have it evaluate true because one of the possible expressions is true. Similarly, all( 'marsh', 'munchkin', 'mink') =~ /^m/ would also be true because all the expressions evaluate to true. Obviously this is something that can be done in perl5 - it just requires more code.

    Now as for actually using Q::S ... no. Its heavier weight than I'd prefer. My most common wish is for the two disjunctions - any of a list of regexes being true and any of a list of strings being equal. I just do those up as plain subs but its not as pretty as perl6 will let me be.

    sub qrany { $_ =~ $_[0] and return 1 for @_[ 1 .. $#_ ]; return 0 } sub eqany { $_ eq $_[0] and return 1 for @_[ 1 .. $#_ ]; return 0 }
      5 == any( 1 .. 10 )

      I can see some usefulness in this, but it operates basically as a range statement. So it does simplify the following by a bit:

      for (1 .. 10) { print "$_\n" if ($var == $_); }

      Unless there's a simpler way to do this. Same goes for the all example you provided. As for Perl 6, do you know if these were covered in the apocolypses yet?

        That is exactly what any() does. It superimposes all of its values into a single scalar and operations on it touch all values. So if you use it in a logical operation like numeric equality - a disjunction has a true value if any of the potential operations have a true value. The point to making this a core feature is that it is syntactically easier to say things like $foo == any( $bar, $baz ..... ). Or my favorite - do the same thing for the m operator.

        You'll find junctions in Apocalypse 4 though I gather its actualy more of an operator thing which is apocalypse 3. *shrug*.

Re: Useful uses of Quantum::Superpositions?
by dragonchild (Archbishop) on Apr 04, 2003 at 14:49 UTC
    Personally, I think it's an extremely useful set of statements. For example, I have been having to do the following:
    my @Required = qw( ... ); my @Non_Zero = qw( ... ); unless ((grep { $row->{$_} eq '' } @Required) || (grep { $row->{$_} == 0 } @Non_Zero)) { # Do stuff here with $row now that we have all the # Required and Non_Zero fields verified... } else { &complain($row); }
    Instead, that would be better written as:
    if (all(@{$row}{@Required}) ne '' && all(@{$row}{@Non_Zero}) != 0) { # Do stuff here ... } else { &complain($row); }
    The first is a crazy way of doing it, but it's what's needed to make it work. I'd much rather have any and all, but I'm not allowed to use them in production code. *pouts*

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

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

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