Course of Raku / Advanced / Modules / Modules basics / Exercises / Use the converter
Solution: Use the converter
Here is a possible solution to the task.
Code
The program, temperature.raku:
use Temperature;
sub MAIN($celsius) {
say c-to-f($celsius);
}🦋 You can find both source files in the exercises/advanced/modules-basics/use-temperature directory.
Output
$ raku -I. temperature.raku 100
212Comments
use Temperatureloads the module and imports its exportedc-to-fsubroutine, so the program can call it directly.sub MAIN($celsius)receives the command-line argument, so the temperature to convert is chosen when the program is run rather than hard-coded. Run without an argument, Raku prints a usage message automatically.The module must be reachable, which is why the program is run with
-I.so that Raku looks forTemperature.rakumodin the current directory. The conversion of100°C gives212°F.