Stupid Perl 6 Ideas While Sick

Ovid on 2008-06-09T22:27:36

Somehow, being sick seems to bring out the stupid in me. Or maybe I'm brilliant. I don't know. However, I just realized that I want the following to be legal in Perl 6.

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 I want subsets to be allowed to mutate their variable. If that works, I think we can allow proper constraint programming in Perl 6. With the above example, imagine dragging your crosshair and the target zone automatically moves. Or moving the target zone and your crosshair automatically stays inside. No funky rules need to get sprinkled in your code. It's built into the type definition!

The downside is mysterious "action at a distance". The upside is a powerful tool that was previously the domain of logic programming languages. Perl 6 is simple at its basic level (much simpler than Perl 5!), but its advanced capabilities can open up worlds of programming that we've not even thought of yet.

Update:

Jonathan Worthington said you can make that work with this:

subset Crosshair of Point where <-> $_ {
    $_.inside_of($target_area) 
    ||
    $target_area.has_moved
      ?? $_.move_inside($target_area)
      :: $target_area.move_outside($_)
};