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


V unit2mult = [‘arshin’ = 0.7112, ‘centimeter’ = 0.01,     ‘diuym’   = 0.0254,
               ‘fut’    = 0.3048, ‘kilometer’  = 1000.0,   ‘liniya’  = 0.00254,
               ‘meter’  = 1.0,    ‘milia’      = 7467.6,   ‘piad’    = 0.1778,
               ‘sazhen’ = 2.1336, ‘tochka’     = 0.000254, ‘vershok’ = 0.04445,
               ‘versta’ = 1066.8]
 
:start:
assert(:argv.len == 3, ‘ERROR. Need two arguments - number then units’)
Float value
X.try
   value = Float(:argv[1])
X.catch
   exit(‘ERROR. First argument must be a (float) number’)
V unit = :argv[2]
assert(unit C unit2mult, ‘ERROR. Only know the following units: ’unit2mult.keys().join(‘ ’))
 
print(‘#. #. to:’.format(value, unit))
L(unt, mlt) sorted(unit2mult.items())
   print(‘  #10: #.’.format(unt, value * unit2mult[unit] / mlt))