我已经有一段时间没有做 Erlang 了,所以我正在练习,但我不再明白了 :(
-module(conversion).
-export([convert/1, convertMeteoCelcius/1]).
convert({celcius, Degres}) -> {farenheit, (Degres * 1.8) + 32};
convert({celcius, Degres}) -> {celcius, Degres};
convert({farenheit, Degres}) -> {celcius, (Degres - 32)/1.8};
convert({farenheit, Degres}) -> {farenheit, Degres}.
convertMeteoCelcius([], [Result])
-> [Result];
convertMeteoCelcius([{City, {Unit, Temp}}|Rest], [Result])
-> convertMeteoCelcius([Rest], [{City, convert({celcius, Temp})}, Result]).
convertMeteoCelcius([Raw]) -> formatMeteoCelcius([Raw], []).