What does -fm mean as a suffix for a runtime function name?

424 views
Skip to first unread message

Gregory Golberg

unread,
Jul 5, 2016, 10:38:08 PM7/5/16
to golang-nuts
Hi all,

Consider this example: https://play.golang.org/p/uy6rPFu6Z9

Which prints

main.Foo 
main.(*T).Bar-fm

What does -fm mean?

-g

Matt Harden

unread,
Jul 5, 2016, 11:21:19 PM7/5/16
to Gregory Golberg, golang-nuts
I'm not sure what it stands for (function from method?). But note that this is a Method Value https://golang.org/ref/spec#Method_values, so it's distinct from the method itself, which doesn't have a receiver already supplied.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gregory Golberg

unread,
Jul 6, 2016, 12:04:21 AM7/6/16
to Matt Harden, golang-nuts
Yes, it is noted - I specifically made this example like so. But why?

If I were to parse the Name() string I could still figure out that this is a method - because main.(*T).Bar-fm shows that it's on type T. 

So what's the point of the suffix?

Matt Harden

unread,
Jul 6, 2016, 12:20:08 AM7/6/16
to gri...@alum.mit.edu, golang-nuts
To distinguish it from main.(*T).Bar, which is a different thing (the method without receiver already supplied).

Gregory Golberg

unread,
Jul 6, 2016, 1:11:27 AM7/6/16
to Matt Harden, golang-nuts

Jakob Borg

unread,
Jul 6, 2016, 7:24:54 AM7/6/16
to Gregory Golberg, Matt Harden, golang-nuts
2016-07-06 7:10 GMT+02:00 Gregory Golberg <gri...@alum.mit.edu>:
This is the difference Matt is referring to:


//jb

Gregory Golberg

unread,
Jul 15, 2016, 2:16:02 AM7/15/16
to golang-nuts, gri...@alum.mit.edu, matt....@gmail.com
Ah, Jakob, thanks - did not see this before.

What's the semantic difference though, I'm not getting it.

roger peppe

unread,
Jul 15, 2016, 9:26:50 AM7/15/16
to Gregory Golberg, gri...@alum.mit.edu, golang-nuts, matt....@gmail.com

The semantic difference is that Type.Method takes the receiver as its first argument, whereas value.Method does not (the value is part of the closure context, which is why creating a function in this way incurs an allocation).


--

Gregory Golberg

unread,
Jul 16, 2016, 1:55:55 AM7/16/16
to roger peppe, golang-nuts, Matt Harden
Ah got it , thanks... 

To clarify for others: https://play.golang.org/p/opxR_ZpX3R

Reply all
Reply to author
Forward
0 new messages