Tag Archives: reflect

Function call by name in Golang

The golang’s function is a code block like C’s, but it can also be assigned to a variable as its other types.

If you are not familiar with the function, Codewalk: First-Class Functions in Go should be a good starting point for you. Already known it? Let’s go on.

First of all, look at this PHP codes:

<br />
function foobar() {<br />
    echo &quot;Hello Golang\n&quot;;<br />
}<br />
$funcs = array(<br />
    &quot;foobar&quot; =&gt; &quot;foobar&quot;,<br />
    &quot;hello&quot;  =&gt; &quot;foobar&quot;,<br />
);<br />
$funcs[&quot;foobar&quot;]();<br />
$funcs[&quot;hello&quot;]();<br />

It will print:

<br />
mikespook@mikespook-laptop:~/Desktop$ php foobar.php<br />
Hello Golang<br />
Hello Golang<br />

Continue reading Function call by name in Golang