What class should include "5 kilograms"?

stan at stanheckman.com stan at stanheckman.com
Wed Nov 11 21:21:30 UTC 1998


< make dimensioned quantities into subclass of Number. >

< file in new coercion methods from squeak central. >

< write three simple methods adaptToFloat, adaptToFraction, and adaptToInteger>

< everything just works >

Hey this new coercion package is great. Really easy to use.

< realize I'm supposed to also write adaptToDimensionedNumber >

< it too is easy to write, and everything still just works >

Yep, this coercion package is wonderful.

< realize I ought to *send* adaptToDimensionedNumber messages >

Sure, that will be no problem, this coercion package is wonderful.

< write some really ugly code >

Um, well, kind of wonderful, I guess.

< potter some more with the code >

Better, but coercions are still merely "kind of wonderful". :-)

Here's what I found awkward: The coercion method has us cast numbers up
to a more general number type, then do an operation between two
objects of the general type. But in the course of that operation, I
found that I sometimes had to check to see whether one of the objects
was "really" of the less general type. (We don't want to raise
anything to the power "3 meters".) So my first iteration of the code
was turning Floats into DimensionedNumbers with no dimensions, then,
because I could no longer tell from their type, asking them to iterate
over their dimensions and check that they were all zero. Yuck.

The current version (http://stanheckman.com/a/98h/glimpsedotter) uses
a helper class DimensionlessNumber that lives at the same level of the
coercion hierarchy and knows how to do arithmetic with dimensioned
numbers. This is not so awful, but not as nice a fit with the coercion
scheme as Integer, Fraction, and Float manage.

-- 
Stan





More information about the Squeak-dev mailing list