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


 
NB. Use, linux.
NB. $ /usr/local/j64-801/bin/jconsole j.ijs 8 meter
 
UNIT2MULT =: /:~ _ ".&.>@:{:@:]`1:`]}"1<;._2@:(,&':');._2 '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,'
 
exit 3 : 0 :: 1: a: -.~ _3 {. ARGV
 if. 3 ~: # y do. smoutput 'ERROR. Need two arguments - number then units'
 else.
  VALUE =: _ ". _2 {:: y
  if. _ = | VALUE do. smoutput 'ERROR. First argument must be a (float) number'
  else.
   UNIT =: {: y
   UNITS =: 0&{"1 UNIT2MULT
   if. UNIT-.@:e.UNITS do. smoutput 'ERROR. Only know the following units: ' , deb , ,&' '&> UNITS
   else.
    smoutput deb(,,&' '&>_2{.y),'to:'
    smoutput UNITS ,. (VALUE * (< 1 ,~ UNITS i. UNIT) {:: UNIT2MULT) %&.> {:"1 UNIT2MULT
   end.
  end.
 end.
)
 