Comments (4)
It's not a "static variable". Such a concept doesn't exist in Go. It's just a
variable.
Original comment by [email protected]
on 1 Apr 2012 at 8:38
- Changed state: Invalid
from go-tour.
I knew there is no static variable in Go. But, I think this method will let
someone who want the static variable workable.
Original comment by [email protected]
on 2 Apr 2012 at 3:16
from go-tour.
I want to track the number of times a method is called, and wanted to know if
this could be done in Go.
I applied the code snippet above to solve my problem, but no luck.
func f() func() int {
i := 0
return func() int { i++ ; return i }
}
func meth(){
for i := 0; i < 2; i++ {
next := f()
println(next())
println(next(), next())
}
}
func main() {
meth()
}
O/P:
1
2 3
1
2 3
How do I make sure the value is retained between iterations here? I'm new to
Go, so any help or suggestions would be greatly appreciated!
Original comment by [email protected]
on 2 Feb 2013 at 12:42
from go-tour.
This is not the right place for such a discussion. Please take your question to
the mailing list by sending mail to [email protected]
Thanks.
Original comment by [email protected]
on 4 Feb 2013 at 5:09
from go-tour.
Related Issues (20)
- Patch for /content/tour.article HOT 2
- Fix assignment syntax in "Mutating maps" HOT 5
- Slide 15 of Tour (Type conversions) correction
- Patch for /solutions/loops.go HOT 2
- Patch for /solutions/loops.go HOT 3
- Adding import fmt to tour #38 breaks it HOT 3
- "Type conversions": maybe change example to match the point the text is trying to make about explicit conversions
- ui: When clicking "syntax off": Uncaught TypeError: Cannot read property 'setOption' of undefined HOT 2
- No Solution for HTTP Handlers HOT 4
- Patch for /solutions/webcrawler.go HOT 2
- Fix a small typing mistake HOT 1
- Feature request: gotour should remember the content of the edit boxes HOT 4
- tree/tree.go always returns the same trees between subsequent runs HOT 1
- Patch for /solutions/webcrawler.go
- Slices Exercise Produces an Error HOT 1
- Go Tour UI - Table of Content scrollbar inaccessible HOT 2
- Type Stringer is an interface, not a struct HOT 2
- update link to "Go's Declaration Syntax" article
- Go Tour shows blank white page
- Stringers exercise - Tour of Go HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-tour.