Front page | perl.perl6.language | Postings from February 2005

## Fwd: Junctive puzzles.

From:
Thomas Yandell
Date:
February 10, 2005 04:52
Subject:
Fwd: Junctive puzzles.
Message ID:
e7ee6fd4050210024215dd71ff@mail.gmail.com
```Sorry if you get this twice (and slightly different), but I posted it
off list by mistake.

---------- Forwarded message ----------
From: Thomas Yandell <thomasyandell@gmail.com>
Date: Thu, 10 Feb 2005 10:22:44 +0000
Subject: Re: Junctive puzzles.
To: Matthew Walton <matthew@alledora.co.uk>

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

Is it perhaps the comments that are wrong, rather than the code?

my \$x = any(1,2,3,4,5,6,7);
if(is_prime(\$x) # expression evaluates to any(2,3,5,7)
and is_even(\$x) # expresion evaluates to any(2, 4, 6)
# at this point the boolean expression evaluates to any(2) - is this
the same as 2?
and \$x > 2) # expression evaluates to any(3,4,5,6,7)
# so result is false
# \$x is still any(1,2,3,4,5,6,7)

Is this right?

Is the following comment correct?

my \$x = any(2,3,4,5) and any(4,5,6,7); # \$x now contains any(4,5)

Tom

```