0

I'm trying to create a service where a user needs to operate over a data and can manipulate it in numerous ways, so I'm not aware of the manipulations at the time of compiling of my program. One way to achieve this is to give the user a function with data as param. Which landed me in the following direction.

  1. Dynamically create a function
  2. Dynamically linking a function after compiling it separately.

I'm open to suggestions. If you have other ways to achieve the end goal.

1 Answer 1

2

If you don't like this as an answer I can move to the comment section, but it's rather long that's why I put here in the answer section.

  1. Dynamically Dispatched Method: The only way to have dynamically dispatched methods is through an interface. Methods on a struct or any other concrete type are always resolved statically.

  2. Closure: Go supports anonymous functions, which can form closures. Anonymous functions are useful when you want to define a function inline without having to name it.

  3. Dyncamically call method on Interface:

Please let me know if that helps you to understand the concept in golang.

Sign up to request clarification or add additional context in comments.

2 Comments

I went through all the suggestions, but what I was hoping for was a way to define a function. All the above-mentioned methods are only good if the function is already defined. Thanks for responding.
As far as I know, that may not works. May I ask you, why u need to do that ? can u give some example in another language that u used like in python or something.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.