[squeak-dev] Quantities and Units

Ben Coman btc at openInWorld.com
Thu Jan 12 15:26:47 UTC 2012


Gabriel Cotelli wrote:
> Hi Ben,
> We use Aconcagua in our financial app (
> http://www.squeaksource.com/Aconcagua.html). Well, our version of Aconcagua
> (probably have some changes now). We are running it in VA Smalltalk and
> GemStone/S, and at the time the port to Pharo/Squeak/VW was easy. There's
> also a Paper available.<http://stephane.ducasse.free.fr/Teaching/CoursAnnecy/0506-M1-COO/aconcagua-p292-wilkinson.pdf>
> The
> package have a good number of test cases that probably can serve as
> examples. If you're implementing this kind of thing is a good idea to learn
> a little about Dimensional
> analysis<http://en.wikipedia.org/wiki/Dimensional_analysis>
>
> Hope it helps,
> Gabriel
>
> On Sun, Jan 8, 2012 at 2:21 AM, Ben Coman <btc at openinworld.com> wrote:
>
>   
>> I am implementing a model defined with quantity data having {value,
>> multiplier, unit} where
>> multiplier is  m, c, k, M, etc
>> unit is V, A, Hz, W, etc
>>
>> So I am looking for what quantities/units packages are around before
>> trying to write my own.
>>
>> I have downloaded [1] and had a poke around there with the tests.  Are
>> there any further examples around of how to use it and to define new units?
>>  I notice that Voltage=Joules/Columb is not defined.
>>
>> Is anyone have any familiar with ports of packages mentioned here [2] [3]
>> [4] from other platforms?
>>
>> cheers, Ben
>>
>> [1] http://www.squeaksource.com/**Units.html<http://www.squeaksource.com/Units.html>
>> [2] http://www.cincomsmalltalk.**com/publicRepository/**Quantities.html<http://www.cincomsmalltalk.com/publicRepository/Quantities.html>
>> [3] http://www.smalltalking.net/**goodies/Dolphin/<http://www.smalltalking.net/goodies/Dolphin/>(scroll to bottom)
>> [4] http://comments.gmane.org/**gmane.comp.lang.smalltalk.**
>> squeak.general/55894<http://comments.gmane.org/gmane.comp.lang.smalltalk.squeak.general/55894>
>>
>>     
Thanks for the pointers Gabriel and Stef.  I've read the paper and it is 
nice to have a detailed background on this. So now I have Aconcagua 
installed and am experimenting setting up units 'newton' and 'joule' as 
shown in the code at the bottom of this post.  Now line 008 (called from 
line 016) is failing since line 010 tries to find 'newton' in the 
'units' dictionary but cannot since it was stored instead by line 014 as 
key: 'meter.kilogram/second^2' - due to line 006 as shown in the 
attached image [1] - which is due to 'name' calling 'nameForOne' which 
is...
    DividedUnit>>nameForOne
        ^numerator name asString , '/' , denominator name asString

I then noticed that section Future Work of the paper says "We have not 
implemented any kind of functionality to allow well known composed units 
to be named, such as Joule (equivalent to m*m*Kg/s*s )."   Has anyone 
else progressed "named composed units" since 2005?

For my try, the closest example I found is method 
'UnitsTestResource>>createMinute' which ultimately works because method 
'name'  fulfilled by...
    ProportionalDerivedUnit>>nameForOne
        ^nameForOne        
where the instanceVariable 'nameForOne' is set at object creation.

I could add a similar instanceVariable to DividedUnit and perhaps have...
    DividedUnit>>nameForOne
       nameForOne
            ifNil: [^numerator name asString , '/' , denominator name 
asString]
            ifNotNil: [ ^nameForOne ].

but I'm not sure what that might break... Any advice would be appreciated.

cheers, Ben

[1] DividedUnit Inspector on Newton.png


Code reference for above discussion...
----
"Based on UnitsTestResource>>setup have the following code to implement 
units 'newton' and 'joule'  "
"Naming"
"001" UnitsTestResource>>newtonName  
"002"     ^'newton'          
"003" UnitsTestResource>>jouleName      
"004"     ^'joule'
"Creating"
"005" UnitsTestResource>>createNewton    
"006"     ^(self kilogram * self meter) / ( self second * self second)
"007" UnitsTestResource>>createJoule    
"008"     ^(self newton) * (self meter)
"Accessing"
"009" UnitsTestResource>>newton         
"010"    ^units at: self newtonName
"011" UnitsTestResource>>joule       
"012"    ^units at: self jouleName
---
"and where existing addUnit is defined as..."
"013" UnitsResource>>addUnit: aUnit 
"014"     units at: aUnit name put: aUnit.      "units is a Dictionary"
"I appended the following to existing UnitsTestResource>>setup..."
"015"         self addUnit: self createNewton.
"016"         self addUnit: self createJoule.
---
"as a reference for creating a named unit there is existing..."
"017 UnitsResource>>createMinute
"018"     ^ProportionalDerivedUnit baseUnit: self second 
conversionFactor: 60 named: self minuteName
----

-------------- next part --------------
A non-text attachment was scrubbed...
Name: DividedUnit Inspector on Newton.png
Type: image/png
Size: 9652 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20120112/00902742/DividedUnitInspectoronNewton.png


More information about the Squeak-dev mailing list