Dipping My Toe In

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



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: