Also worth pointing out: there is a J addon helping with this:
load 'math/uu'
uu '1 mug' NB. string notation
1.000E-9 kg
'elephant' uu 1;'wt.human' NB. boxed notation
┌────┬────────┐
│0.05│elephant│
└────┴────────┘
NB. Verb adding values if units correspond (Assuming boxed notation).
addu =: ('Noncompatible units'"_)`((+&>&{. ; {:@])&uu) @.
(compatible_uu_&>&{:)
(1;'elephant') addu (1;'wt.human')
┌────┬──┐
│3570│kg│
└────┴──┘
(1;'N') addu (1;'s')
Noncompatible units
Presumably the tabula addon, or the CAL addon can do even better, but
documentation for CAL says you should use Tabula, and Tabula seems utterly
broken in J803. It also does not feel it would integrate well into a
standard J workflow ...
2015-04-12 1:54 GMT+02:00 Raul Miller <[email protected]>:
> Ok, that makes more sense.
>
> I can still see problems, but at least they require other examples.
>
> Thanks,
>
> --
> Raul
>
> On Sat, Apr 11, 2015 at 6:47 PM, Vijay Lulla <[email protected]> wrote:
> > The statement in the article is: "We must distinguish :@ (prefixing)
> > from :* (unit multiplication) because Kilo :@ Gram can, for example,
> > be added to something expressed in Gram s, but Meter :* Gram cannot."
> >
> > I infer this as: Gram can be added to Kilogram (of course by fixing
> > for appropriate unit conversions) but it cannot be added to "Meter :*
> > Gram". I think that's what Bob meant.
> >
> > On Sat, Apr 11, 2015 at 6:10 PM, Raul Miller <[email protected]>
> wrote:
> >> That one strikes me as odd, also.
> >>
> >> Perhaps it's to prevent people from calculating center of mass?
> >>
> >> But why would anyone want to prevent that type of calculation?
> >>
> >> --
> >> Raul
> >>
> >> On Sat, Apr 11, 2015 at 5:41 PM, Devon McCormick <[email protected]>
> wrote:
> >>> Hi Bob -
> >>>
> >>> this sounds interesting but why would Meter*Gram be forbidden? If I'm
> >>> calculating Newtons, I want Kg * M/s^2, don't I?
> >>>
> >>> Regards,
> >>>
> >>> Devon
> >>>
> >>> On Sat, Apr 11, 2015 at 4:37 PM, Robert Bernecky <
> [email protected]>
> >>> wrote:
> >>>
> >>>> In the recent discussion on typing in J, I cited the Gimley Glider
> >>>> and the Mars Climate Orbiter as events in which confusion over
> >>>> units of measure caused expensive problems and near-disaster
> >>>> (disaster in the case of the MCO).
> >>>>
> >>>> This morning, I was reading the SIGPLAN Haskell Symposium '14
> >>>> Proceedings, and found this article:
> >>>>
> >>>> http://www.cis.upenn.edu/~eir/papers/2014/units/units.pdf
> >>>>
> >>>> By way of introduction, the paper cites the same two events, and also
> >>>> cites (bottom of page 1) a paper that gives more of the same.
> >>>> The paper is worth reading, IMO, because the authors create
> >>>> DIMENSIONs: mass, length, density, volume, etc., that are
> >>>> independent of units (kilogram, furlong, fortnight).
> >>>> They also introduce two kinds of combinators (adverbs) that
> >>>> can modify the dimensions, e.g,:
> >>>>
> >>>> type Velocity = Length: / Time
> >>>> type Kilogram = Kilo :@ Gram NB. Kilo is prefix, not unit
> >>>>
> >>>> This lets them do things such as multiplying Kilograms times Gram
> >>>> (and getting the right answer) , while forbidding Meter * Gram.
> >>>>
> >>>> I think these folks have some good ideas that could be exploited
> >>>> in J and APL to everyone's benefit.
> >>>>
> >>>> Bob
> >>>>
> >>>> --
> >>>> Robert Bernecky
> >>>> Snake Island Research Inc
> >>>> 18 Fifth Street
> >>>> Ward's Island
> >>>> Toronto, Ontario M5J 2B9
> >>>>
> >>>> [email protected]
> >>>> tel: +1 416 203 0854
> >>>>
> >>>> ----------------------------------------------------------------------
> >>>> For information about J forums see
> http://www.jsoftware.com/forums.htm
> >>>>
> >>>
> >>>
> >>>
> >>> --
> >>> Devon McCormick, CFA
> >>> ----------------------------------------------------------------------
> >>> For information about J forums see http://www.jsoftware.com/forums.htm
> >> ----------------------------------------------------------------------
> >> For information about J forums see http://www.jsoftware.com/forums.htm
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm