> -----Original Message-----
> From: Luke Palmer [mailto:[EMAIL PROTECTED]
> Sent: Saturday, December 13, 2003 9:30 AM
> To: Andy Wardley; Larry Wall; Perl6; [EMAIL PROTECTED]
> Subject: Re: enums and bitenums
> 
> 
> Andy Wardley writes:
> > Larry Wall wrote:
> > > Well, we can't use -> because we're using that for something else.
> > > But it's certainly true that we'll have to have some mechanism for
> > > disambiguating Color.green from Blackberry.green.  After all,
> > > 
> > >     Blackberry.green == Color.red
> > > 
> > > Or maybe it's
> > > 
> > >     Blackberry::green == Color::red
> > 
> > [...]
> > 
> > > I don't know the syntax for
> > > disambiguating on the green end yet.  Maybe one of
> > > 
> > >     $foo ~~ Color::green
> > >     $foo ~~ Color.green
> > >     $foo ~~ Color[green]
> > > 
> > > Or maybe something else.
> > 
> > How about a single colon?
> > 
> >      Color:green 
> >
> > This is the same syntax employed in XML namespaces and URIs, 
> for example:
> > 
> >     <xml xmlns:color="http://example.com/xml/color.xsd";>
> >       <color:green/>
> >     </xml>
> > 
> > Don't tell me, we can't use : because we're using that for something
> > else.  :-)
> 
> Well, yes.  It's used in the operator position already for the indirect
> object syntax, so I don't think that'll fly.


Also, as Larry pointed out there's likely to be the need to talk about multiple values.
Color[green|red] is better in a lot of ways than Color::green|Color::red.


> Keeping with the color example, let's think about what this is doing:
> 
>     $foo ~~ green
> 
> That ought to work even if you set "green" by saying:
> 
>     $foo.Color = (0,1,0);
> 
> So it seems more that "green" is doubling as a predicate and a value.
> Indeed, you could think of setting something to green as setting it to
> "pure green" (0,1,0), but testing "green" as anything that looks
> greenish -> $r,$g,$b { $g > $r + $b }.
> 
> Maybe it's a subtype[1] of the property with a default value?
> 
> That gets me thinking about how to declare that.  If a subtype is like a
> parameter to the class that the class didn't really declare, I could
> imagine a syntax like this:
> 
>     constraint Color[green] { $.g > $.r + $.b }
> 
> That makes me woosy, though.  Maybe digging up the adverbial modifier
> C<where> should stir some ideas.
> 
>     constraint green is Color { $.g > $.r + $.b }
> 
>     my Color where green $spinach;

I don't understand where you were going with that.

> Maybe we'd better leave that one buried.


Speaking of predicate/value mixups:

  role green 
    does Color[$.g > $.r + $.b]
    does {
      method .VALUE { return (0,1,0); }
    };

Then:

  my Color $g = green;
  
  my Color $c = (random(), random(), random());

  if $c == $g {
    print "That's GREEN!";
  }
  elsif $c ~~ green {
    print "Well, it's greenish";
  }


> For some reason, subtypes don't feel like roles to me.  They're not so
> much behaviors are they are constraints... on behavior.  Like the
> opposite of roles, actually. 
> 
> Oh, we were talking about enums, right?  Um.  Yeah. 
> 
> Luke
> 
> [1] There's a term to add to the vocab sheet.  AFAIK, a subtype is a
> variation on a normal type that has some constraint applied to it.
> Think vague.
> 

Reply via email to