google / cel-go

Fast, portable, non-Turing complete expression evaluation with gradual typing (Go)
https://cel.dev
Apache License 2.0
2.21k stars 220 forks source link

Late Function Bindings in Go Cel Evaluation #356

Open mswest46 opened 4 years ago

mswest46 commented 4 years ago

Currently, function definitions must be provided in the parsing step, so data relevant to their definition must be available at that step. This request is to support binding a function at activation time instead. As a use case example, I'd like to write a function has_tag :: string -> bool whose implementation checks membership in a list tags that is only available at evaluation time and remains hidden from the expression writer.

JimLarson commented 4 years ago

We're discussing a generalization of this - allow functions to access the full Activation, not just the supplied variables. This way you could bind tags as a variable at runtime in the normal way, but it would be hidden from the expression if you omit it from the declarations at type check time. This would require a separate flavor of overload which would accept something like func(interpreter.Activation, ...ref.Val) ref.Val.