enabled passing functions as parameters in function call

This commit is contained in:
Celestino Amoroso 2024-04-14 07:38:28 +02:00
parent f1afbf9b49
commit 43e631f2e8
2 changed files with 10 additions and 5 deletions

View File

@ -24,11 +24,11 @@ func TestExpr(t *testing.T) {
succeeded := 0
failed := 0
// inputs1 := []inputType{
// {`1 ? {"a"} : {"b"} ? ["a"] {"A"} :["b"] {"B"}`, "B", nil},
// }
inputs1 := []inputType{
{`f = func(op){op()}; f(func(){2})`, int64(2), nil},
}
for i, input := range inputs {
for i, input := range inputs1 {
var expr Expr
var gotResult any
var gotErr error

View File

@ -89,7 +89,12 @@ type funcDefFunctor struct {
func (functor *funcDefFunctor) Invoke(ctx ExprContext, name string, args []any) (result any, err error) {
for i, p := range functor.params {
if i < len(args) {
ctx.setVar(p, args[i])
arg := args[i]
if functor, ok := arg.(Functor); ok {
ctx.RegisterFunc(p, functor, 0, -1)
} else {
ctx.setVar(p, arg)
}
} else {
ctx.setVar(p, nil)
}