Rebol3 Code Examplex
Old Russian measure of length
Traditional Russian length unit conversion.
Rebol [
title: "Rosetta code: Old Russian measure of length"
file: %Old_Russian_measure_of_length.r3
url: https://rosettacode.org/wiki/Old_Russian_measure_of_length
]
russion-length: function/with [
"Convert a value from one Russian unit to another."
value [integer! decimal!] "Value to convert"
from [word!] "Source unit"
to [word!] "Target unit"
][
unless all [
src: units/:from
dst: units/:to
][ ;; unknown unit — raise an error listing all valid unit names
do make error! reform ["Unit must be one of:" keys-of units]
]
value * src / dst ;; convert via meters as the common intermediate
][
units: #[
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
]
]
russion-units: [
arshin centimeter diuym fut kilometer liniya
meter milia piad sazhen tochka vershok versta
]
print as-yellow " 1 meter to:"
foreach unit russion-units [
printf [-10 ": "][unit russion-length 1 'meter unit]
]
print ""
print as-yellow " 1 versta to:"
foreach unit russion-units [
printf [-10 ": "] [unit russion-length 1 'versta unit]
]Output:
1 meter to:
arshin: 1.40607424071991
centimeter: 100.0
diuym: 39.3700787401575
fut: 3.28083989501312
kilometer: 0.001
liniya: 393.700787401575
meter: 1.0
milia: 0.000133911832449515
piad: 5.62429696287964
sazhen: 0.468691413573303
tochka: 3937.00787401575
vershok: 22.4971878515186
versta: 0.000937382827146607
1 versta to:
arshin: 1500.0
centimeter: 106680.0
diuym: 42000.0
fut: 3500.0
kilometer: 1.0668
liniya: 420000.0
meter: 1066.8
milia: 0.142857142857143
piad: 6000.0
sazhen: 500.0
tochka: 4200000.0
vershok: 24000.0
versta: 1.0