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

  • Home
  • SEARCH
  • 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 7614705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:28:18+00:00 2026-05-31T02:28:18+00:00

I have this sample code where I’m defining an array but it doesn’t compile:

  • 0

I have this sample code where I’m defining an array but it doesn’t compile:

$ cat a.go
package f
func t() []int  {
    arr := [] int {
        1,
        2
    }
    return arr
}

oreyes@OREYES-WIN7 ~/code/go
$ go build a.go
# command-line-arguments
.\a.go:5: syntax error: unexpected semicolon or newline, expecting }
.\a.go:7: non-declaration statement outside function body
.\a.go:8: syntax error: unexpected }

However if I remove the newline it works:

$ cat a.go
package f
func t() []int  {
    arr := [] int {
        1,
        2 }
    return arr
}

oreyes@OREYES-WIN7 ~/code/go
$ go build a.go

Howcome?

  • 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-05-31T02:28:19+00:00Added an answer on May 31, 2026 at 2:28 am

    Simply put a comma (,) at the end of all lines containing elements of the array:

    arr :=  [] func(int) int {
        func( x int ) int { return x + 1 },
        func( y int ) int { return y * 2 }, // A comma (to prevent automatic semicolon insertion)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So far, I have this code sample: ... int nbytes =0; vector<unsigned char> buffer;
I have this code sample: class Number { int i; public: Number(int i1): i(i1)
I have this sample code for async operations (copied from the interwebs) public class
I have a this aspx-code: (sample) <asp:DropDownList runat=server ID=ddList1></asp:DropDownList> With this codebehind: List<System.Web.UI.WebControls.ListItem> colors
In sample code, I have seen this: typedef enum Ename { Bob, Mary, John}
There is probably is simple fix for this but I currently have code similar
i have this sample code i want to use. I'm not sure where to
I have this sample code: <ControlTemplate Content={Binding .}/> What does the point mean here
suppose we have this next sample code: while(some condition){ lock1.lock(); . . } the
I have this snippet from apple sample code LazyTableImages . In the code below

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.