Unit values

Adde adde at trialcode.com
Wed Apr 27 14:02:42 PDT 2005


Brian Rice wrote:

> I think the attention you two have given this library has reached a 
> threshhold. If you read the source, you'll see that I just ported it 
> from Smalltalk-80 and didn't care too much about it.
>
> Right now, you two care more about it than I do. So put your fingers 
> where your mouth is, and code up these changes yourself and use darcs 
> send so I can apply them.
>
> Patches speak louder than words! :)
>
> On Apr 27, 2005, at 7:41 AM, David Hopwood wrote:
>
>> Brian Rice wrote:
>>
>>> On Apr 26, 2005, at 11:50 AM, Adde wrote:
>>>
>>>> I added the px method to Number traits to be able to say: 1 px 
>>>> instead of 1 with: px, don't know if that's a good idea but it 
>>>> certanly makes it easier to use. The other methods are just 
>>>> placeholder for XML-specific formatting.
>>>
>>> The "px" message idea has occurred to me before, and I think what 
>>> I'll do is have the BaseUnit creation method name:abbrev: create the 
>>> method for you so you don't have to do it. How does that sound? :)
>>
>>
>> Suggestion: merge the UnitValue and Unit types, by having a unit behave
>> as 1 of that unit, i.e. px = 1*px.
>>
>> Then only multiplication is needed to form a UnitValue, e.g. 42*px.
>> Similarly examples like "(72*px) / in" would work automatically. This
>> design also allows derived units and conversion factors to be expressed
>> more simply.
>
> -- 
> Brian T. Rice
> LOGOS Research and Development
> http://tunes.org/~water/
>
I'm fine with implementing the changes myself if and when I feel I 
understand the problem well enough.
One thing I'm wondering that has nothing to do with the Units library is 
if there is any way to dispatch on a slot of an object.
Something like this maybe:

uv unit@(Pixel traits) printOn: p@(SVG Printer traits) [
  uv value printOn: p.
  uv unit printOn: p.
].

And if that isn't possible, do you think it'd be a good idea to add a 
slot to BaseUnit that contains the base for it's values so that you can 
dispatch on that instead? It wouldn't mean any changes to the code using 
the library since BaseUnit could init the slot itself. Then you cold do 
things like this:

uv@(Pixel baseValue traits) printOn: p@(SVG Printer traits) [
  uv value printOn: p.
  uv unit printOn: p.
].

/Adde




More information about the Slate mailing list