Hacker News new | ask | show | jobs
by frou_dh 3397 days ago
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.
1 comments

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.