in reply to Problem using Quantum::Superpositions

It seems to be working - i mean, it assigns '20' - haven't really tried to understand it at all :-) - when you assing in list context:
#! perl -w use strict; local ($,=" - ", $\="\n"); use Quantum::Superpositions; sub min { eigenstates( any(@_) <= all(@_) ) } sub max { eigenstates( any(@_) >= all(@_) ) } my @array = qw/ 10 15 20 10 7 4 /; my ($t1) = all(); print ($t1); my ($t2) = max(@array); print $t2; print max(@array), (($t1) = max(@array)), $t2; __DATA__ this results in: all() 20 20 - 20 - 20
-- Joost downtime n. The period during which a system is error-free and immune from user input.

Replies are listed 'Best First'.
Re: Re: Problem using Q::SP's
by BrowserUk (Patriarch) on Jul 10, 2002 at 15:43 UTC

    Thanks Joost. ({grin} at RMGir)

    I had a 'feeling' it was a context problem as noted. I just didn't know what to do about.

    So, spelling out what is going on here (just incase I'm not the only DSOB that reads this):

    With my $var = all(); when all() checks wantarray() to determine its calling context, it gets SCALER and therefore returns the count of the states that matched the condition.

    With my ($var)  = all();, wantarray() gives ARRAY so all() (or probably eigenstates()) returns the list (in this case containing just one value) that matched the condition.

    I know I'll be (rightfully and usefully) corrected if this is wrong:)

      Close, BrowserUK.

      I don't have the Q::SP source handy, but what's probably happening is that all() always returns an array, and then it's your assignment that determines whether that array is evaluated in scalar or list contexts.

      In a scalar context, an array always returns the count of the elements, while in a list context, an element-by-element assignment is done, so

      my ($x)=all();
      captures the first value of all()'s result in $x.
      --
      Mike