tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

transform-list.tri (661B)


      1 !import bd2c14d6db6b69308a5252a8e839705a55d30e815f012900b094315263e08d81 as List
      2 !import 7f87549d587fa8c3be88af0ea988db3adcc3b35f1ffb48973553491b075614db as Math
      3 !export total
      4 !export double
      5 
      6 -- Apply the same function to every item.
      7 double number = Math.multiply number 2
      8 numbers = [2 4 6]
      9 
     10 -- map takes a function, then a list. Here it produces [4 8 12].
     11 doubled = List.map double numbers
     12 total = List.sum doubled
     13 -- Evaluate total with Natural number: the result is 24.
     14 -- Add import supplies List and Math.
     15 
     16 -- Try double 5 with Natural number: the result is 10.
     17 -- Exercise: make double multiply by 3. The new total should be 36.
     18 -- Next: Making a choice.