TablaM provides a small selection of functions available:
Operations like "
+,-,*,/" are in fact functions internally. With them is also available:
sum function operate on relations of numbers and return the total:
fun sum(rel:[Number]) = Number
sum(1.0f) -- = 1.0f sum([1; 2; 3]) -- = 6
avg function operate on relations of numbers and return the average of the values:
fun avg(rel:[Number]) = Number
avg(1.0f) -- = 1.0f avg([1; 2; 3]) -- = 2
min & max
max functions accept a relation and return the min or max value, accordingly.
Note that these are logical functions, not math. So it operates on ANY value following the total order of types.
fun min(rel:Rel) = Rel fun max(rel:Rel) = Rel
min([1; 2]) -- = 1 max([1; 2]) -- = 2 min([true, 1; 2]) -- = true max([1; 2; "Hello"]) -- = "Hello"
To operate with IO (files, stdin, stdout, sockets, etc):
print & println
println functions accept a list of values and convert them to
String and output the result to the stdout, which is commonly the terminal.
fun print(values: Any...) fun println(values: Any...)
print("hello") print("world") println("hello") println("world")
open function load a
.csv file, scan the header and return it as a relation. Note that this functionality is temporal. Later will be correctly used to open any kind of file.
fun open(path: Path) = Rel
-- With a csv file like -- id,ref,name -- 1,24236-097,Noodles let products := open("products.csv")
read_to_string function take a
File and load the contents as a
fun read_to_string(file: File) = String
let products := open("products.csv") let txt := read_to_string(products)
save function turn the relation in a
String, then save the results to the disk. Note that this functionally not yet work correctly.
fun save(rel:Rel, path: Path)
let products := [ id:Int, ref:Str, name:Str; 1,"24236-097","Noodles"] save(products, "products.csv")