incomplete docs for stdlib
This commit is contained in:
parent
b941df68e1
commit
e1913fea2c
2 changed files with 21 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue