Ovid wrote:
Well, looking at the examples that you and Jonathan listed, I see I
should refine my question. For example:
subset Crosshair of Point where {
$_.inside_of($target_area)
||
$target_area.has_moved
?? $_.move_inside($target_area)
:: $target_area.move_outside($_)
};
In other words, I think we could get proper constraint programming if a
subset can mutate its variable.
By default, block parameters (including $_) are readonly, but you can
use the <-> pointy block syntax, which declares its parameters "is rw",
or just do so explicitly. Here's one of the ways, and I think this would
work (or at least is the correct syntax):
subset Crosshair of Point where <-> $_ {
$_.inside_of($target_area)
||
$target_area.has_moved
?? $_.move_inside($target_area)
:: $target_area.move_outside($_)
};
On the other hand, this could lead to mysterious action at a distance. The
losses are significant, but the wins seem absolutely fascinating.
Well, you are explicitly declaring the rw nature of the constraint right
there in the signature, so it's easy enough to know that it might change
things without having to look through the code inside the block to
check. So I think it's not quite so spooky, or at least the spookiness
is declared up front. :-)
Jonathan