Hacker News new | ask | show | jobs
by coldtea 3397 days ago
>and even if they were, I don't think Go will help you find an arbitrary function by name at runtime

You'd be surprised:

https://golang.org/pkg/reflect/#Value.MethodByName

1 comments

That's about methods and not functions ;) Yes indeed, if you are partying in the context of a specific value, you can use that reflection. My language is not "OO"-aware though. Maybe after I give the embedded mode more real world use then that aspect will be unavoidable.
A, yes. In that case you could expose all the functions you want in advance, in some map that's accessible by (string) name.

    // Static
    
    err = rootEnv.DefineForeignProcedure("sprintf", fmt.Sprintf)

    # Runtime

    (let x 2
         (sprintf "%d cubed is %d"
                  x
                  (pow x 3)))

    => "2 cubed is 8"
Yep, that's what I was talking about.