Merge branch 'documentation' of https://gitlab.com/whom/shs into documentation

This commit is contained in:
Aidan 2020-07-19 15:04:35 -07:00
commit ae9ca588d6
No known key found for this signature in database
GPG key ID: 327711E983899316
2 changed files with 28 additions and 3 deletions

View file

@ -56,6 +56,12 @@ func NumCast(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
*
* Example: (+ 1 2)
*/
func Add(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
var res float64
@ -98,7 +104,12 @@ func Add(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
return t
}
func sub(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
/* subtract N args from the final arg
* takes N args, returns nil if improper args given
*
* Example: (- 2 1)
*/
func Sub(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
var res float64
var sub float64
@ -148,7 +159,12 @@ func sub(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
return t
}
func mult(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
/* multiplies N arguments
* returns nil if an improper argument is given
*
* Example: (* 1 2)
*/
func Mult(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
res := 1.0
in = in.Eval(f, a, false)
@ -190,7 +206,13 @@ func mult(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
return t
}
func div(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
/* divide N arguments
* the first argument is divided by each subsequent argument in order
* returns nil if an improper argument is given
*
* Example (/ 25 5)
*/
func Div(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
var res float64
in = in.Eval(f, a, false)

View file

@ -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{