Dave Whipp wrote:
> The definition of the Complex type seems a little weak. A few things:
> 
> To get the Cartesian components of the value there are two methods ("re" 
> and "im"). In contrast there is just one method "polar" to return the 
> polar components of the value

Not quite, .abs returns one of the polar coordinates (the magnitude), so
only a method is missing that returns the angle.

Any ideas for a good name?

> I'm not sure that this asymmetry is a good 
> thing. Contrast with Rat which has both separate accessors and the 
> "nude" method (a name that could possibly be improved to avoid 
> adult-content filters)

suggestions welcome.

> The next thing I notice is that the return value of "polar" is defined 
> as a "Seq" (as is the return value of "nude"), with an English-language 
> definition of that the (exactly) two members of the sequence are. Surely 
> it is possible in a perl6 signature to define the return value more 
> formally, something like:
> 
>    our multi method polar (Complex $nim: --> [ Real $mag where 0..Inf, 
> Real $angle where -π ..^ π ]) is export { ... }

If you put this into a signature, it is checked on every call to that
method and thus slows down execution. If you want a formalization that's
not part of the signature, you find that in the test suite.

> Finally, anyone using complex numbers probably wants a "conjugate" 
> method and/or operator postfix:<*> almost as much as they want unary-minus:
> 
>    $mag = sqrt( $z * $z* );

$max = abs $z;

I agree that conjugate is a good idea, but please don't use postfix:<*>
for that. It's defined as a term and as an infix already, and in
signatures also as a prefix. There's also the infix:<**> and the term
**, and I won't even start to talk about regexes and other DSLs or twigils.
I'm really opposed to giving the asterisk yet another meaning.

Cheers,
Moritz

Reply via email to