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

It's impossible to recurse a anonymous function in Go without workarounds. #226

Closed
gopherbot opened this Issue Nov 16, 2009 · 9 comments

Comments

Projects
None yet
4 participants
@gopherbot

gopherbot commented Nov 16, 2009

by helmwo:

What steps will reproduce the problem?
1.
func main() {
  a := func() {
    ... // how to access this anonymous func here?
  }
  a();
}

What is your $GOOS?  $GOARCH?

linux 386 - but that does not matter.

Which revision are you sync'ed to?  (hg log -l 1)

changeset:   3975:b51fd2d6c160
tag:         tip
user:        Kevin Ballard <kevin@sb.org>
date:        Tue Nov 10 20:05:24 2009 -0800
summary:     Implement new emacs command M-x gofmt

Please provide any additional information below.

I'd introduce a pseudo function called recurse() that allows to recurse 
over functions. I'd even introduce this for named functions.
@gopherbot

This comment has been minimized.

Show comment
Hide comment
@gopherbot

gopherbot Nov 16, 2009

Comment 1 by jason.catena:

A solution to this should at least consider replacing recursion with iteration for tail 
calls.

gopherbot commented Nov 16, 2009

Comment 1 by jason.catena:

A solution to this should at least consider replacing recursion with iteration for tail 
calls.
@gopherbot

This comment has been minimized.

Show comment
Hide comment
@gopherbot

gopherbot Nov 16, 2009

Comment 2 by helmwo:

Iteration is nice where it is useful. Same for recursion. Recursion can walk around 
trees, while iteration walks arrays. So there is at least a little bit need for 
recursion in a language...

gopherbot commented Nov 16, 2009

Comment 2 by helmwo:

Iteration is nice where it is useful. Same for recursion. Recursion can walk around 
trees, while iteration walks arrays. So there is at least a little bit need for 
recursion in a language...
@gopherbot

This comment has been minimized.

Show comment
Hide comment
@gopherbot

gopherbot Nov 16, 2009

Comment 3 by consalus:

I believe you can just do:
var a func();
a = func() {...}
and that should work.
At least, a variation of that worked fine for me.

gopherbot commented Nov 16, 2009

Comment 3 by consalus:

I believe you can just do:
var a func();
a = func() {...}
and that should work.
At least, a variation of that worked fine for me.
@gopherbot

This comment has been minimized.

Show comment
Hide comment
@gopherbot

gopherbot Nov 16, 2009

Comment 4 by helmwo:

3: Yes, but imagine you change "a" somewhere.

gopherbot commented Nov 16, 2009

Comment 4 by helmwo:

3: Yes, but imagine you change "a" somewhere.
@griesemer

This comment has been minimized.

Show comment
Hide comment
@griesemer

griesemer Nov 17, 2009

Contributor

Comment 5:

At the moment there is a clear work-around as has been pointed out.

Status changed to Thinking.

Contributor

griesemer commented Nov 17, 2009

Comment 5:

At the moment there is a clear work-around as has been pointed out.

Status changed to Thinking.

@gopherbot

This comment has been minimized.

Show comment
Hide comment
@gopherbot

gopherbot Nov 17, 2009

Comment 6 by JQBalter:

"Iteration is nice where it is useful. Same for recursion. Recursion can walk around 
trees, while iteration walks arrays. So there is at least a little bit need for 
recursion in a language..."
I believe comment 1 was about implementing recursive tail calls as iteration, not for
eliminating recursion.
"Yes, but imagine you change "a" somewhere."
Seriously?
anonymous_func_for_a := func() {
    ... anonymous_func_for_a(); ...
}
a := anonymous_func_for_a;
b := a;
a = something_else;
b() // works fine

gopherbot commented Nov 17, 2009

Comment 6 by JQBalter:

"Iteration is nice where it is useful. Same for recursion. Recursion can walk around 
trees, while iteration walks arrays. So there is at least a little bit need for 
recursion in a language..."
I believe comment 1 was about implementing recursive tail calls as iteration, not for
eliminating recursion.
"Yes, but imagine you change "a" somewhere."
Seriously?
anonymous_func_for_a := func() {
    ... anonymous_func_for_a(); ...
}
a := anonymous_func_for_a;
b := a;
a = something_else;
b() // works fine
@rsc

This comment has been minimized.

Show comment
Hide comment
@rsc

rsc Nov 17, 2009

Contributor

Comment 7:

Owner changed to r...@golang.org.

Contributor

rsc commented Nov 17, 2009

Comment 7:

Owner changed to r...@golang.org.

@gopherbot

This comment has been minimized.

Show comment
Hide comment
@gopherbot

gopherbot Nov 19, 2009

Comment 8 by isilando:

These work-around-s are far from clean. There oughts to be a keyword for self-
referencing for anonymous functions, in every language which supports them.
But as the word "ought" indicates, this is pretty low in the priority of issues.

gopherbot commented Nov 19, 2009

Comment 8 by isilando:

These work-around-s are far from clean. There oughts to be a keyword for self-
referencing for anonymous functions, in every language which supports them.
But as the word "ought" indicates, this is pretty low in the priority of issues.
@robpike

This comment has been minimized.

Show comment
Hide comment
@robpike

robpike Nov 21, 2009

Contributor

Comment 9:

There's a clear workaround.  If there's a real fix, it's just to allow nested function 
declarations.

Status changed to WontFix.

Contributor

robpike commented Nov 21, 2009

Comment 9:

There's a clear workaround.  If there's a real fix, it's just to allow nested function 
declarations.

Status changed to WontFix.

@gopherbot gopherbot added the wontfix label Nov 21, 2009

@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.