All~
On Tue, 08 Feb 2005 17:51:24 +0100, Miroslav Silovic <[EMAIL PROTECTED]> wrote:
[EMAIL PROTECTED] wrote:
Well, we see the same kind of thing with standard interval arithmetic:
(-1, 1) * (-1, 1) = (-1, 1) (-1, 1) ** 2 = [0, 1)
The reason that junctions behave this way is because they don't collapse. You'll note the same semantics don't arise in Quantum::Entanglement (when you set the "try to be true" option).
But you can force a collapse like this:
my $x = 4 < $j; if $j < 2 { say "never executed" }
By which I mean:
my $x = 4 < $j; if $x < 2 { say "never executed" }
Uh, I'm not sure this does what I think you wanted to say it does. ;) $x is a boolean, unless < returns a magical object... in which case, the magical part of $x ought to be a reference to the original $j, no?
I'm wonding if we should allow a method that returns a junction that is allowed to collapse the original:
if 4 < $j.collapse and $j.collapse < 2 { say "never executed"; }
But that's probably not a good idea, just by looking at the implementation complexity of Quantum::Entanglement. People will just have to learn that junctions don't obey ordering laws.
Well, I suspect that junctions will have to be references and just collapse every time. Observe:
my $x = any(1, 2, 3, 4, 5); print "SHOULD NOT RUN" if (is_prime($x) && is_even($x) && $x > 2);
This only works if $x collapses. Same for matching junctioned strings:
my $a = any (<a b c>); print "Boo!" if $a ~ /a/ and $a ~ /b/ and $a ~ /c/;
(perhaps I meant to use ~~, I don't quite remember :) )
Either way, autocollapsing juntions is a Good Thing IMHO, and the only remaining confusion (to go back to my initial post) is that the only case that doesn't work is when you instance a junction twice as a pair of same literals:
print "SUCCESS, unfortunately" if (is_prime(any(1, 2, 3, 4, 5)) && is_even(any(1, 2, 3, 4, 5)) && any(1, 2, 3, 4, 5) > 2);
Hope I'm making sense. Been a hard day at work. ;)
What if junctions collapsed into junctions of the valid options under some circumstances, so
my $x = any(1,2,3,4,5,6,7); if(is_prime($x) # $x = any(2,3,5,7) and is_even($x) # $x = any(2) and $x > 2) # $x = any()
This is Just Wrong, IMO. How confusing is it going to be to find that calling is_prime($x) modifies the value of $x despite it being a very simple test operation which appears to have no side effects?
As far as I can see it, in the example, it's perfectly logical for is_prime($x), is_even($x) and $x > 2 to all be true, because an any() junction was used. If an all() junction was used it would be quite a different matter of course, but I would see is_prime() called on an any() junction as returning true the moment it finds a value inside that junction which is prime. It doesn't need to change $x at all.
In a way, you're sort of asking 'has $x got something that has the characteristics of a prime number?' and of course, $x has - several of them, in fact (but the count is not important).
