On Wed, Feb 16, 2005 at 01:06:22PM +0000, Nigel Sandever wrote:
> 
> Any chance that you could provide one or two simple but realistic examples of 
> using Junctions and their operators?

I'll give it a shot, but keep in mind that I'm somewhat new to this 
also.  :-)

First, junctions are an easy way to represent the relationships
"any", "all", "one", or "none".  So, where we once had to say:

   if ($x==$a or $x==$b or $x==$c or $x==$d) { ... }

we can now say

   if $x == any($a, $b, $c, $d) { ... }

Similarly, where we once had to say

   if (grep { $x == $^z } @list) { ... }
   if (grep { $x == $^z } @list) == 0 { ... }
   
we can now say

   if $x == any(@list) { ... }
   if $x == none(@list) { ... }

And for fun, try writing the equivalent of 

   if $x == one($a, $b, $c, $d) { ... }

without a junction.  (Okay, one can cheat with C<grep>.)

A programmer can easily use these without having to worry about the
notions of "autothreading" or "superpositions" or the like, and
their translations to English are fairly obvious.  I suspect that
constructs like the above will be the majority of use for junctions.

Things start to get "weirder" when we start storing junctions into
variables, and/or passing those variables/junctions into subroutines.
But I think this is not *too* far removed from the idea of placing a 
subroutine or a rule into a scalar -- i.e., using a scalar to represent
something more than a single-valued primitive type.  Thus, just as one
can write

   $x = new CGI;
   $y = rule { \d+ };
   $z = sub { ... };

and then use $x, $y, and $z later on for an object, rule, and sub 
(which may have a variety of side-effects associated with them), it makes
sense that one can write

   $w = any(@list);

and then use $w to refer to the junction later.  And a programmer who
does this is taking on some responsibility for understanding that $w
isn't one of the "trivial" scalars anymore (same as for $x, $y, and $z).

However, one difference is that when one typically uses an object, rule,
or subroutine in a scalar there is some syntax that makes their nature
apparent.  Some feel that Junctions might be just a bit "too magical"
in this respect (e.g., Luke has made some syntactic suggestions to try
make the existence/threading of a junction more apparent).

Pm

Reply via email to