--- Austin Hastings <[EMAIL PROTECTED]> wrote:
>
> --- "Adam D. Lopresto" <[EMAIL PROTECTED]> wrote:
> > #Actually, how do we define this?
> > method asBoolean(Complex $self:){
> > return $self.real || $self.imag;
> > }
> >
> >
> > ...
> >
> >
> > then somewhere in a function
> >
> > return Complex::new(0,0) but true;
>
> Alternatively, think of the "simple" properties not as C<trait>
> specifications, but as method overrides.
>
> In this case, we're dynamically modifying the method table for the
> object (i.e., dynamically creating a class) such that a given method
> behaves the way we want:
>
> macro true {
> "&.asBoolean { return 1; }"
> }
>
> Complex::new(0,0) but true;
>
> becomes
>
> Complex::new(0,0) but &.asBoolean { return 1; }
>
> (This is syntactic sugar, not a real macro, because it couldn't
> handle the C<if $complex.true> form. Maybe a better macro
> programmer?)
>
>
> > Since Complex already has an implementation of whatever method
> > decides whether it's true or not, wouldn't just applying a property
> > be insufficient to override that?
>
> That would be pointless, wouldn't it?
Going further, what's C<true>?
trait Boolean {
requires <<&.value>>;
method true {+(.value) != 0; }
method false {!?.true}
}
trait true
does Boolean
{
method true { 1; }
method false { 0; }
}
trait true
does Boolean
{
method true { 0; }
method false { 1; }
}
Then:
my $x = 0 but true;
Means
my [ class $_temp0123 is Scalar does true; ] $x = 0;
Of course, when I do:
my $x = 0 but (true|false);
then what happens?
=Austin