Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: receiver-curried method expressions #2280

Closed
bradfitz opened this issue Sep 20, 2011 · 12 comments
Closed

spec: receiver-curried method expressions #2280

bradfitz opened this issue Sep 20, 2011 · 12 comments

Comments

@bradfitz
Copy link
Contributor

We have method expressions of form Type.Method.

This is a wishlist bug for method expressions that curry the receiver, of form
receiver.Method.

type A struct {
   // ...
}

func (a *A) Foo(bar, baz int) {}

b := new(A)
foob := b.Foo  // foob is of type func(int, int)
@bradfitz
Copy link
Contributor Author

Comment 1:

Owner changed to ---.

@robpike
Copy link
Contributor

robpike commented Oct 4, 2011

Comment 2:

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Dec 9, 2011

Comment 4:

Labels changed: added priority-someday, removed priority-low.

@gopherbot
Copy link

Comment 6 by cjmxp2009:

什么时候支持这个功能

@ianlancetaylor
Copy link
Contributor

Comment 7:

There is no schedule or plan for this, it is just an idea.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 8:

Labels changed: added go1.1maybe.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 9:

Labels changed: added size-xl.

@bradfitz
Copy link
Contributor Author

Comment 10:

Adding dependency on issue #4081.
And, adding to this bug the example I've given a few people now of when this is useful:
type T struct {
   once  sync.Once // guards setup of state
   state interface{}
}
func (t *T) initState() {
   t.state = ....
}
func (t *T) someMethod() {
   t.once.Do(t.initState)   // because Do requires type "func()"
   // use t.state
}
Currently we have to either do:
 t.once.Do(func() { t.initState() })
... which generates garbage each time, or give up on the zero value of T and instead
make a constructor:
func NewT() *T {
   t := new(T)
   t.initFunc = func() { t.initState }
   return t
}
func (t *T) someMethod() {
   t.once.Do(t.initFunc)
   ...
}

@rsc
Copy link
Contributor

rsc commented Jan 15, 2013

Comment 11:

Those are not the only choices:
type T struct {
    mu sync.Mutex
    state interface{}
}
func (t *T) someMethod() {
    t.mu.Lock()
    if t.state == nil {
        t.initState()
    }
    t.mu.Unlock()
    ...
}

@rsc
Copy link
Contributor

rsc commented Mar 12, 2013

Comment 12:

[The time for maybe has passed.]

Labels changed: removed go1.1maybe.

@rsc
Copy link
Contributor

rsc commented Mar 15, 2013

Comment 13:

Labels changed: added go1.1.

@rsc
Copy link
Contributor

rsc commented Mar 20, 2013

Comment 14:

This issue was closed by revision 6e15683.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants