diff --git a/stdlib/arith.go b/stdlib/arith.go index a9051eb..5682177 100644 --- a/stdlib/arith.go +++ b/stdlib/arith.go @@ -29,6 +29,10 @@ import ( // perhaps we simply write out arithmetic routines that operate on the strings // then we need not worry about storage length. +/* Cast a string to a number + * Takes 1 argument + * returns nil if fails + */ func num_cast(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token { in = in.Eval(f, a, false) if in.Tag != ast.STRING { @@ -50,6 +54,10 @@ func num_cast(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token { return out } +/* adds N number arguments + * takes N arguments + * returns the sum, or nil if improper arguments were given + */ func add(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token { var res float64 @@ -92,6 +100,9 @@ func add(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token { return t } +/* subtract N args from the final arg + * takes N args, returns nil if improper args given + */ func sub(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token { var res float64 var sub float64 @@ -142,6 +153,9 @@ func sub(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token { return t } +/* multiplies N arguments + * returns nil if an improper argument is given + */ func mult(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token { res := 1.0 @@ -184,6 +198,10 @@ func mult(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token { return t } +/* divide N arguments + * the first argument is divided by each subsequent argument in order + * returns nil if an improper argument is given + */ func div(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token { var res float64 diff --git a/stdlib/stdlib.go b/stdlib/stdlib.go index a243700..d92e754 100644 --- a/stdlib/stdlib.go +++ b/stdlib/stdlib.go @@ -25,6 +25,9 @@ import ( "gitlab.com/whom/shs/util" ) +/* Makes a FuncTable from all functions in the stdlib + * add your function here if you are extending the standard library + */ func GenFuncTable() ast.FuncTable { var stdlib ast.FuncTable stdlib = &map[string]*ast.Function{