On Mon, 2005-03-28 at 15:07, Rod Adams wrote: > Markus Laire wrote: > > So do you actually envision perl6 to allow a junction of units on > > numbers? This would have huge implications, depending on what exactly > > is possible with these units...
> > # import proper MMD-subs for + - * etc... > > use MyUnitConversions; > > > > my $length = 1.3`Meters + 4.6`Yards; > > my $weight = 4`Pounds - 1'Kilograms; > > my $money = 12`¤ + 5.78`£ + 12`US$; > > > > Then, how would I specify the unit of the result? You ask for the unit you want. I'm not sure I like or dislike this syntax, but it's easy enough to see that: 12`¤ is just 12 but ¤ where ¤ is probably an alias for the class (role?) Units::Money::Euro. Addition would be defined in a base class in such a way that conversion to an appropriate intermediate unit would be done and then addition performed. The derived classes would provide addition only for the special case where both operands were in the derived unit (for performance). Now you can ask for whatever you like: say "We have {¤.new $money}¤" Though you might have some snazzy way of saying that. > The real "fun" in determining what should happen with units comes to > when you do operations that _change_ the units. > > my $Current = 5`Amps; > my $Resistance = 10`Ohms; > my $Power = $Current * $Resistance; # Do I get 50`Watts here? Again, if Amps and Ohms know that they can do that, then you're all set. Otherwise, you just construct a new value like so: my Watts $Power = $Current * $Resistance; Which again are probably all aliases for Units::Physics::* -- Aaron Sherman <[EMAIL PROTECTED]> Senior Systems Engineer and Toolsmith "It's the sound of a satellite saying, 'get me down!'" -Shriekback