Dave Whipp wrote:
> Jon Lang wrote:
>>
>>  my ($num, $denom) = $num.^attr; # $num.WHAT == Ratio;
>>  my ($mag, $phase) = Complex::Polar($z).^attr;
>>  my ($re, $im) = Complex::Cartesian($z).^attr;
>>  my ($x, $y) = $vector.^attr »·« ( [1, 0], [0, 1] );
>
> If I'm reading this right, the .^attr is exposing implementation details of
> the object to get its components. To my mind that is not desirable.

The reason that HOW is spelled in allcaps is because it can be used in
undesirable ways.  In particular, whedn you introspect an object,
you're looking at its implementation details.

And really, my whole point is that the implementation details are
(conceptually) the only thing that distinguishes Complex::Polar from
Complex::Cartesian.  More on this below.

> And I think there's a Math error in the 4th line: you don't need the
> components of a vector to do a dot product with that vector -- so it is just
>
>   my ($x, $y) = $vector «·« ( [1, 0], [0, 1] );

True enough.

> Which makes me wonder if all of them are just the dot-product of an object
> with a role (i.e. it uses the .^attr of the role, not the object):

The role may not have a .^attr; in particular, I'd expect the
following to be true:

  role Complex {
    ...
    method re() { ... }
    method im() { ... }
    method abs() { ... }
    method arg() { ... }
  } # no "has" declarations
  class Complex::Cartesian does Complex { has $re, $im; ... }
  class Complex::Polar does Complex { has $abs, $arg; ... }

There's another problem with my proposal, namely the fact that
introspection of a package's component parts shouldn't be expected to
preserve the order of said components.  But setting that aside for the
moment: Complex.^attr ought to return an empty list, since no
attributes were declared in it; Complex::Polar.^attr ought to return a
magnitude and an argument (i.e., an angle); and
Complex::Cartesian.^attr ought to return a real value and an imaginary
value.

-- 
Jonathan "Dataweaver" Lang

Reply via email to