On Thu, 14 Nov 2002, Jonathan Scott Duff wrote:

> On Fri, Nov 15, 2002 at 07:05:26AM +1100, Timothy S. Nelson wrote:
> > --------------------------------------------------------------
> > given ($this) {
> >     when $that_happens { "Have a party" }
> >     when $that_doesnt_happen { "Sing" }
> >     all {
> >             # Do something
> >     }
> >     any {
> >             # Do something else
> >     }
> >     some {
> >             # Do something other
> >     }
> >     none {
> >             # Do something however
> >     }
> > }
> > --------------------------------------------------------------
> 
> So, I was all set to show how this could work with junctions, but then
> I realized that I don't understand them well enough, so here's what I
> came up with:
> 
>       $j0 = $that_happens | $that_doesnt_happen;
>       $j1 = !$that_happens | !$that_doesnt_happen;
>       given ($this) {
>          when $j0 ~~ $that_happens { ... }
>          when $j0 ~~ $that_doesnt_happen { ... }
>          when all($j0) { ... }
>          when any($j0) { ... }
>          when any($j1) { ... }                # "some" Rare, I expect
>          when none($j0) { ... }
>       }
> 
> Is that right?  Is there a better way?  What happens when there's a
> junction on either side of a smart match?

        No doubt you understand them better than I do.  My complete knowledge 
comes from http://archive.develooper.com/perl6-language@;perl.org/msg10178.html
(search for "superpositions").  

        Since I don't understand what ~~ does, I'm not quite sure I understand 
your code.  

        I'll be glad when that virtual mug throwing guy gets the documentation 
for this kind of thing done a bit more, or when synopses for the other 
sections get done, so I don't have to go hunting for this kind of thing any 
more :).  

> 
> >     The basic idea is that you have two "special" variables which I will, 
> > just for now, call $truecount and $falsecount.  Basically, every time one of 
> > the "when" clauses comes up true, it increments truecount; whenever one comes 
> > up false, it increments $falsecount.  The blocks below the given get evaluated 
> > under the following conditions
> > 
> > all: $falsecount == 0
> > any: $truecount > 0
> > some: $falsecount > 0
> > none: $truecount == 0
> 
> -Scott
> 


---------------------------------------------------------------------
| Name: Tim Nelson                 | Because the Creator is,        |
| E-mail: [EMAIL PROTECTED] | I am                           |
---------------------------------------------------------------------

----BEGIN GEEK CODE BLOCK----
Version 3.1
GCS d? s: a-- C++>++++$ US+ P++ L++ E- W+++ N+ w+> M-- V- Y+>++ 
PGP->++ R(+) !tv B++ DI++++ D+ G e>++ h!/* y-
-----END GEEK CODE BLOCK-----


Reply via email to