Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8186711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:18:41+00:00 2026-06-07T02:18:41+00:00

From my reading of the spec: A short variable declaration … is a shorthand

  • 0

From my reading of the spec:

A short variable declaration … is a shorthand for a regular variable
declaration with initializer expressions but no types…

http://golang.org/ref/spec

I would have thought the two were identical:

var f func()
f = func() {
    ...
}

and

f := func() {
    ...
}

But it seems like they’re not. I was trying to wrap a self-recursive function inside of an outer function, but this works:

func myOuter() {
    var f func()

    f = func() {
        f()
    }

    f()
}

But this doesn’t, saying undefined: f in the inner function.

func myOuter() {
    f := func() {
        f()
    }

    f()
}

So what is the difference?
Is there any way to write this with the short-form declaration or I do I have to write it out long-hand?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:18:45+00:00Added an answer on June 7, 2026 at 2:18 am

    f := func() { /* ... */ } is identical to var f func() = func() { /* ... */ } (but only the later one is allowed at the package level). In your specific case, neither of the two variants will work, since the statement will be evaluated from right to left. The solution is – as you have already suggested – to split the statement into two. One for declaring the variable and another for assigning the recursive function to it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn from reading Mozilla documentation for regular expressions, but there's one
Seems like this might be easy, but from reading other SO answers there are
My understanding from reading the specification ( http://www.ietf.org/rfc/rfc2445.txt ) is that the : character
From reading the NERDTree documentation on github, I've learned that I can do such
From reading the Apple Docs on Core Data, I've learned that you should not
From reading the RFC it appears that CID can/must only contain characters from the
It's clear from reading through threads that I can call a PHP function using
I know from reading the assoc. Google group that there is not currently an
What I have been able to grasp from reading the source and documentation from
lets say i created a virtualenv called venv (virtualenv venv) From reading tutorials, i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.