in reply to Nested Quantum::Superpositions

any(all(1,4)) evaluates to any() since in scalar context there's nothing that can evaluate to all(1,4), i.e. to 1 and 4 simulataneously (any is conjunctive).

I've just tried out the example in de docs, and is doesn't seem to work:

my @features = ("tall", "handsome", "rich"); my $ideal = any(all("tall", "handsome", "rich" all("rich", "old"), all("smart", "rich", "Australian")); if (any(@features) eq $ideal) { print "success\n"; } else { print "failure\n"; } print any(@features), "\n"; print $ideal, "\n"; __END__ failure any(handsome,tall,rich) any()
Changing any to all for @features doesn't help matters.
Something's rotten in the Kingdom of Denmark...

I think we'll need Damian on this, -gjb-

Update: Removed the strike-through of the explanation since it seems to be correct after all. The docs are probably wrong.

Replies are listed 'Best First'.
Re: Re: Nested Quantum::Superpositions
by welchavw (Pilgrim) on Nov 06, 2003 at 21:07 UTC

    Thanks for the reply. I'm not sure my grok meter is full yet, though.

    Here's a snippet from the docs...

    More interestingly, since the individual states of a superposition are scalar values and a superposition is itself a scalar value, a superposition may have states that are themselves superpositions:

    $ideal = any( all("tall", "rich", "handsome"), all("rich", "old"), all("smart","Australian","rich") );

    Operations involving such a composite superposition operate recursively and in parallel on each its states individually and then recompose the result. For example:

    while (@features = get_description) { if (any(@features) eq $ideal) { print "True love"; } }

    The any(@features) eq $ideal equality is true if the input characteristics collectively match any of the three superimposed conjunctive superpositions. That is, if the characteristics collectively equate to each of "tall" and "rich" and "handsome", or to both "rich" and "old", or to all three of "smart" and "Australian" and "rich".

    So...I guess I thought that the outer any would distribute across the results of the inner alls without affecting their meaning (if that makes "any" sense)? Maybe I just really don't understand the docs example.

    ,welchavw

Re: Re: Nested Quantum::Superpositions
by runrig (Abbot) on Nov 07, 2003 at 06:17 UTC
    Notice that he never says exactly what goes into @features. You need to put something in which can equal 2 or 3 things at the same time. Interesting, this succeeds:
    if (any(any("tall", "rich")) eq all("tall", "rich")) { print "yes\n"; }
    But this doesn't:
    if (any(any("tall", "rich")) eq any(all("ugly"), all("tall", "rich"))) + { print "yes\n"; }
    Methinks there's a bug lurking in there, but then, you were warned