Dave Whipp wrote: > Moritz Lenz wrote: >> >> Dave Whipp wrote: >>> >>> [cut] 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. > > Attempting to generalize: what we want is an operator that extracts a Seq of > values from an object based on a positive criteria. For string objects, this > description matches the C<comb> method. Generalizing: > > my @words = $line.comb( /\S+/ ); > my ($num, $denom) = $num.comb( :Ratio ); > my ($mag, $phase) = $z.comb( :Complex::Polar ); > my ($re, $im) = $z.comb( :Complex::Cartesian ); > my ($x, $y) = $vector.comb( [1,0], [0,1] ); >
I like the idea of a general mechanism for producing a list of an object's attributes; but I don't think that .comb() is the way to go about it. Rather, I'd use .^attr(). 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] ); -- Jonathan "Dataweaver" Lang