Task

Write a program to perform a conversion of the old Russian measures of length to the metric system   (and vice versa).



It is an example of a linear transformation of several variables.



The program should accept a single value in a selected unit of measurement, and convert and return it to the other units:

vershoks, arshins, sazhens, versts, meters, centimeters and kilometers.



Also see

   Old Russian measure of length


import system'collections;
import system'routines;
import extensions;
 
unit2mult = new Map<string, real>()
    .setAt("arshin",     0.7112r)
    .setAt("centimeter", 0.01r)     
    .setAt("diuym",      0.0254r)
    .setAt("fut",        0.3048r)
    .setAt("kilometer",  1000.0r)   
    .setAt("liniya",     0.00254r)
    .setAt("meter",      1.0r)
    .setAt("milia",      7467.6r)
    .setAt("piad",       0.1778r)
    .setAt("sazhen",     2.1336r)
    .setAt("tochka",     0.000254r) 
    .setAt("vershok",    0.04445r)
    .setAt("versta",     1066.8r);
 
public program()
{
    if (program_arguments.Length != 3)
        { console.writeLine:"need two arguments - number then units"; AbortException.raise() };
 
    real value := program_arguments[1].toReal();    
    string unit := program_arguments[2];
    ifnot (unit2mult.containsKey(unit))
    {
        console.printLine("only following units are supported:",
            unit2mult.selectBy:(x=>x.Item1).asEnumerable());
 
        AbortException.raise()
    };
 
    console.printLine(value," ",unit," to:");
 
    unit2mult.forEach:(u,mlt)
    {
        console.printPaddingLeft(30, u, ":").printLine(value * unit2mult[unit] / mlt)
    }    
}