all: add optional args

This commit is contained in:
2018-05-14 21:48:44 +02:00
parent fae99aedd8
commit ac880c26a6
4 changed files with 139 additions and 101 deletions

View File

@@ -94,16 +94,16 @@ func parseValue(input []string) (*ast.AST, error, []string) {
if input[0][0] == '~' {
fn := ast.AST{ast.Symbol, input[0][1:]}
complement := ast.AST{ast.Symbol, "complement"}
complement := ast.AST{ast.Symbol, "complement"}
res = ast.AST{ast.List, []*ast.AST{&complement, &fn}}
return &res, nil, input[1:]
}
if strings.Contains(input[0], ":") {
comp := ast.AST{ast.Symbol, "compose"}
comp := ast.AST{ast.Symbol, "compose"}
fns := []*ast.AST{&comp}
for _, fn := range strings.Split(input[0], ":") {
astfn := ast.AST{ast.Symbol, fn}
astfn := ast.AST{ast.Symbol, fn}
fns = append(fns, &astfn)
}
res = ast.AST{ast.List, fns}
@@ -116,9 +116,9 @@ func parseValue(input []string) (*ast.AST, error, []string) {
func makeFn(bodyStatements []*ast.AST) ast.AST {
body := ast.AST{ast.List, bodyStatements}
underscore := ast.AST{ast.Symbol, "_"}
underscore := ast.AST{ast.Symbol, "_"}
args := ast.AST{ast.List, []*ast.AST{&underscore}}
fn := ast.AST{ast.Symbol, "fn"}
fn := ast.AST{ast.Symbol, "fn"}
return ast.AST{ast.List, []*ast.AST{&fn, &args, &body}}
}
@@ -140,7 +140,7 @@ func parseToken(input []string) (*ast.AST, error, []string) {
return nil, err, input
}
quote := ast.AST{ast.Symbol, "quote"}
quote := ast.AST{ast.Symbol, "quote"}
res := ast.AST{ast.List, []*ast.AST{&quote, tmp}}
return &res, nil, input
}