Search code examples
smalltalk

Aconcagua measure library - storing BaseUnits


What is the best practice to store base units?

Let's say I want to have a mile unit. So, I implement Number>>#miles, but what is the implementation?

The problem is that: (2 * (BaseUnit named: 'mile')) ~= (2 * (BaseUnit named: 'mile')), so it seems the mile base unit must be a singleton.

So I'd have something like:

Number>>#miles
    ^ self * Mile uniqueInstance

Am I on the right track, or can you think of a better way?


Solution

  • Yes the mile base unit must be a singleton, you can take a look at the Chalten framework which is using Aconcagua, in particular the TimeUnitsGlobal class. For the Number method part, in Chalten it's done this way :

    Number>>#daysMeasure
        ^TimeUnits day with: self
    

    Although I have an issue with the way it's done there because I can't found a way to use Fuel with such units after that.