GithubHelp home page GithubHelp logo

Comments (4)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.