Posts Tagged ‘Numeric’

Dipping My Toe In

April 1, 2010

On Tuesday I went ahead and added the Numeric and Real roles to Rakudo. Initially they only applied to Rat and Complex, but jnthn++ added a patch that allows roles to be added to classes when they are augmented, and now Int and Num also do Real.

I then tried moving the abs method to the Real role, and ran into trouble. Apparently multi methods in roles are NYI in Rakudo, and fail hard. Luckily this was pretty easy to work around in this case, as abs doesn’t really need the multi in the short term. That let me get Real.abs up and running properly. (I might add that Real.abs is a case study in how getting the abstractions right makes the code very simple: it is a one line method that should work for any Real that properly handles the less-than operator and negation.)

The next issue I hit was when I tried to add Numeric.abs as well. Apparently if Real does Numeric, and both have abs methods, Rakudo fails hard. This has also been reported to jnthn, and I hope there will be patch for both these errors in the next few days.

At any rate, I definitely consider this a good start. I think my next step is probably to figure out a better (if still short-term) name than RealX


Numeric Plan of Attack

March 30, 2010

As you may know, the Perl Foundation has accepted my grant proposal to work on implementing the Numeric and Real roles in Rakudo. I’d like to thank the Perl Foundation and Ian Hague for this support, and Jonathan Worthington for his help in putting the proposal together. I’m quite excited to be working on this, and hope to have a solid implementation ready in time for Rakudo *.

I’d like to sketch out my current plan of attack on this grant. I’ve already blogged twice on changes I think the Numeric/Real spec needs. Those ideas still need some more thought, and I’d like to address Larry Wall’s suggestion for ordering Complex numbers too. Glancing over the spec just now, I think there are a few functions that ended up in the wrong role, so I’ll address that in another post soon. These are all intended to be practical changes to make the current roles work better.

I’m planning on diving right in by creating empty roles Numeric and Real and assigning them to the appropriate numeric classes. I think that can work with minimal disruption to Rakudo, and then once tests have been established for this, I will push on and start moving functions to their new locations one-by-one. (If it turns out this does create disruptions for Rakudo, I’ll branch Rakudo to work on it — but right now I expect that won’t be needed.)

As I said in the grant proposal, one thing I think is important is making it as straightforward and simple as possible to create new numeric types. As such, I plan on creating tests for this ability as well, checking how new classes fit in with the existing ones.

Schedule-wise, I expect to only get light work done in the next ten days or so, as we are in the midst of moving. Once we are settled in I plan on seriously tackling the work in an attempt to get significant work on it done by the April 22 Rakudo release.