Interpreted functions were represented in an inconsistent way in the frame: as a node pointer by default, and wrapped in a function wrapper for maps. We now simply use the default (*node) representation, as elsewhere, so values can be assigned, passed and called as for the other types. The alternative (generating a function wrapper) is more complex, costly and reserved for cases where the interpreted function can be called from the runtime. Test that a map of functions can store both binary functions from used packages and interpreted ones. Fixes #1090.
23 lines
385 B
Go
23 lines
385 B
Go
package main
|
|
|
|
import "strings"
|
|
|
|
func f(s string) string { return "hello " + s }
|
|
|
|
func g(s string) string { return "hi " + s }
|
|
|
|
var methods = map[string]func(string) string{"f": f}
|
|
|
|
func main() {
|
|
methods["i"] = strings.ToUpper
|
|
methods["g"] = g
|
|
println(methods["f"]("test"))
|
|
println(methods["g"]("test"))
|
|
println(methods["i"]("test"))
|
|
}
|
|
|
|
// Output:
|
|
// hello test
|
|
// hi test
|
|
// TEST
|