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.

Adrian
  • 42,911
  • 6
  • 107
  • 99
utkarsh sharma
  • 149
  • 2
  • 12

1 Answers1

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.

James Sapam
  • 16,036
  • 12
  • 50
  • 73
  • 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. – utkarsh sharma Jul 24 '19 at 20:45
  • 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. – James Sapam Jul 30 '19 at 18:08