functions.tri (715B)
1 !import 7f87549d587fa8c3be88af0ea988db3adcc3b35f1ffb48973553491b075614db as Math 2 !export * 3 4 -- Reuse a calculation with different inputs. 5 double number = Math.multiply number 2 6 -- Evaluate double 6 with Natural number. 7 -- Result: 12. 8 -- Add import supplies Math, including multiplication. 9 10 -- number is a parameter: each call supplies its value. 11 -- Try double 9: the same definition now returns 18. 12 13 -- A function can also take more than one input. 14 add left right = Math.add left right 15 -- Try add 4 7 with Natural number: the result is 11. 16 17 -- Exercise: change double to multiply by 3, and give it the name triple. 18 -- Then evaluate triple 6. Update the expression to use your new name. 19 -- Next: Working with lists.