|string to literal for function exists||RoboTamer||8/25/12 7:35 PM|
I am working on a function exists, is function function.
Seams I am almost there, but I can't figure out how to replace main in ValueOf(main) with a variable.
I tried Unquote with no success.
You can test what I have so far at the play.go
|Re: string to literal for function exists||Andy Balholm||8/25/12 8:07 PM|
The reflect package does not support looking up functions by name. The reason for this is that the linker reduces the size of compiled programs by discarding functions that it knows will never be called.
|Re: [go-nuts] string to literal for function exists||Jesse McNelis||8/25/12 11:41 PM|
On Sun, Aug 26, 2012 at 12:35 PM, RoboTamer <grue...@gmail.com> wrote:Go doesn't allow this because there are certain advantages to disallowing it.
1. The compiler can identify and remove code that will never be called
at compile time, reducing the size of the executable.
2. You can remove code from your code base and know at compile time
whether or not that code could ever be called at runtime. Making it
easier to refactor code.
If Go allowed you to convert a string in to a function pointer then we
would lose the two advantages above. It's a trade off.
It's common when coming to a new programming language to just keep
trying to write code like you've done in another language. Each
language is different and requires a different approach. If you're
trying to do this in Go then it's likely your coming at your problem
from the perspective of a dynamically typing language programmer and
you should rethink how you'd design your program.
|Re: [go-nuts] string to literal for function exists||Rémy Oudompheng||8/25/12 11:46 PM|
On 2012/8/26 RoboTamer <grue...@gmail.com> wrote:Packages are not subject to reflection. Use a map to map names to
functions (see template.FuncMap for an example).
|Re: [go-nuts] string to literal for function exists||RoboTamer||8/26/12 4:52 AM|
Thanks, this might just work, I can create this map on the fly from a file or database
|Re: [go-nuts] string to literal for function exists||mikespook||8/26/12 6:42 AM|
于 Sun, 26 Aug 2012 04:52:34 -0700 (PDT)
RoboTamer <grue...@gmail.com> 写道:
|Re: [go-nuts] string to literal for function exists||RoboTamer||8/26/12 8:23 PM|
于 Sun, 26 Aug 2012 04:52:34 -0700 (PDT)"Function call by name in Golang"
Thank you mikespook, this is it