use v6;
use Test;
plan *;
my @array = (1, 2, 2, 3, 4, 5, 5, 5, 5, 6, 7, 8);
ok([<=] @array, "array is sorted properly");
done_testing;
If anyone has a notion why this fails, I'm all ears. I'd love to clear this up.
use v6;
use Test;
plan *;
my @array = (1, 2, 2, 3, 4, 5, 5, 5, 5, 6, 7, 8);
ok([<=] @array, "array is sorted properly");
done_testing;
x^N
. You can check out the complete source if you'd like; for the most part, Perl 6's nifty hyperoperators and list operations make the implementation simple.<<+>>
pads with the last element of the shorter array, with is completely mathematically unsuitable in this case. So here was my first stab at implementing Polynomial addition:$a.coefficients, 0 <<+>> $b.coefficients, 0
. As it is, this adds an additional zero coefficient each time it is called, which in the long run will be trouble. But it can be counteracted by adjusting the Polynomial constructor to remove "trailing" zero coefficients. (This is how Polynomial.pm is currently implemented.) (Errr... perhaps I spoke too soon; I'm having difficulty successfully deleting the trailing zeros. Sigh.) <<+>>
how to extend. His suggestion of :extend-with
seems like a weak name to me, but I do think it seems like the proper Perl 6ish way to handle this issue.
$u
parameter. This is the payoff for not forcing $u
to be a Num; we can pass a polynomial instead and get a polynomial out.$p == 0
case and one for $p > 0
. The latter will work perfectly when passed a polynomial for $u
. (At least in theory; there may be issues with Rakudo bugs, of course.) The former, however, actually needs to know what the numeric value of $u
is. Originally I planned to somehow overload the polynomial class to have a value for this purpose. But as far as I know, to make that work, I'd have to overload prefix:<+>
-- and last time I checked, that didn't work in Rakudo.$u
. But once you're thinking about doing that, it's time to face the facts: even the hypothetical "cool" implementation of N we have is grotesquely inefficient for reasonably complicated knot vectors. .Str
and .perl
functions for KnotVector and Nubs...
*
and +
.@.knots
, the prior degree's array of N values called @N_prev
, and $end = @.knots.end
, the calculation looks like this:$u «-« @.knots[0..($end - $p - 1)]
, which is very definitely a dwimmy hyperoperator. And that's just the tip of the iceberg -- in fact, I have yet to simplify this calculation enough to make Rakudo happy with it. It seems Rakudo is really not ready to handle deeply nested hyperoperators yet. You can work around it in this case by using the Texas version of the operator. It also seems there is some odd glitch the second time you call »O/«
: you get the error message "ResizablePMCArray: Can't pop from an empty array!" even simplifying the use until it is very obviously right.ComplexRole
, capturing the idea of numbers with real and imaginary parts (either or both of which might be zero), and implementing a slew of standard mathematical functions that work on complex numbers. subset RealRole of ComplexRole where { $^z.im == 0.0 }
. The most notable added method would be Num
, but there would probably also be a lot of RealRole-specific mathematical functions, as they can be a lot simpler than the complex equivalents.where
, but the RationalRole subset of RealRole would mostly just add numerator and denominator methods. And finally we would have subset IntegerRole of RationalRole where { $^q.denominator == 1 }
.loop ($x = 1.0; $x <= 2.0; $x += (1/9))
, it's a crapshoot whether you get the "2.0" or not, and even if you do, it might actually be 1.99998 or something like that. Usually in these cases getting the exact ending value is highly desirable (as it is an edge case).loop ($x = 1; $x <= 2; $x += (1/9))
should give the exact list 1, 10/9, 11/9, 12/9, ... 17/9, 2. But that doesn't help with the fencepost, and the general problem is very ugly to solve this way!)Range
with :by
might do the trick. Unfortunately, I don't see Perl 6 specs for how :by
actually works in this sort of case, and as far as I know, it's not actually implemented yet to test. At any rate, I'd like to suggest that :by
does actually handle this case, if possible (ie if an element of the range is within epsilon of the to
value, then the to
value is returned instead). And I'd like to suggest two more modifiers, something like :size(N)
to specify that the Range should return N values, with the :by
value calculated as appropriate, and :sections(N)
to specify that the Range should return N+1 values.:size
function should do. I believe that it is properly set up to be lazy, while laziness is available. Note that if you use integer parameters, it will return Rats!