in reply to An infix fix

use Quantum::Superpositions qw( any all ); if ( all( undef, 2, 0, 'x' ) ) { print "They're all true!\n"; } else { print "At least one is false!\n"; } if ( any( undef, 2, 0, 'x' ) ) { print "At least one is truee!\n"; } else { print "They're all false!\n"; }

And, they will be in Perl6.

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re^2: An infix fix
by stvn (Monsignor) on Mar 22, 2005 at 18:02 UTC
    And, they will be in Perl6.

    And they will have the much better name of Junctions. See Synopsis 9 and 3 for more info. They also currently work in Pugs as well:

    #!/usr/bin/pugs use v6; if ( undef() & 2 & 0 & 'x' ) { print "They're all true!\n"; } else { print "At least one is false!\n"; } if ( undef | 2 | 0 | 'x' ) { print "At least one is truee!\n"; } else { print "They're all false!\n"; }
    NOTE: The undef() in the first 'if' currently needs to be there or it confuses the parser, this is a Pugs-Bug though, so it will be fixed eventually.

    -stvn

      I see a difference between this and the any() / all() usage. How would you do

      if (all(@results)) { ... }

      using the

      if (x & y & z) { ... }

      style of coding it?

      /me is asking a question just in case I am missing something, since I don't see the relation between the two styles. One can process a list, the other cannot.

      --MidLifeXis

        You cannot actually. You do Junctions on lists by using the any()/all()/one() functions. Which correspond to the '&', '|' and '^' Junction operators. You can see some tests for this here. If you look in the 'misc_junctions.t' file, you will see some examples of any()/all() and one().

        -stvn
Re^2: An infix fix
by tlm (Prior) on Mar 22, 2005 at 14:35 UTC

    Quantum superposition!? Heavens! Isn't that a bit like using a thermonuclear device to kill a fly? Maybe this another case of one of those regrettable module names. :-)

    I must learn more about it

    the lowliest monk

      It's more of a joke by the esteemed Damian Conway. Remember - most of Perl is a thermonuclear device ... which is why it's so good at swatting flies. :-)

      Being right, does not endow the right to be rude; politeness costs nothing.
      Being unknowing, is not the same as being stupid.
      Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
      Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

        And the ones you miss will glow in the dark there by making pass two much easier...

        --hsm

        "Never try to teach a pig to sing...it wastes your time and it annoys the pig."