in reply to Re: Problem using Q::SP's
in thread Problem using Quantum::Superpositions

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:)

Replies are listed 'Best First'.
Re: Re: Re: Problem using Q::SP's
by RMGir (Prior) on Jul 10, 2002 at 16:03 UTC
    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