Skip to content
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

duplicate argument error #42

Open
ghost opened this issue May 6, 2015 · 1 comment
Open

duplicate argument error #42

ghost opened this issue May 6, 2015 · 1 comment

Comments

@ghost
Copy link

ghost commented May 6, 2015

I'm getting a 'duplicate argument name' with the below code

func location(name, city string) (name, continent string) {
    switch city {
    case "New York", "LA", "Chicago":
        continent = "North America"
    default:
        continent = "Unknown"
    }
    return
}

func main() {
    name, continent := location("Matt", "LA")
    fmt.Printf("%s lives in %s", name, continent)
}
go version go1.4.2 darwin/amd64
@jeanmatheussouto
Copy link

Hi @aidylewis

This error is because you use the same variable name to input and output func location(name, city string) (name, continent string). You should use different names, and your function should return two values not one.

An example:

func location(city string) (myCity, region, continent string) {
    myCity = city
    switch city {
    case "Los Angeles", "LA", "Santa Monica":
        region, continent = "California", "North America"
    case "New York", "NYC":
        region, continent = "New York", "North America"
    default:
        region, continent = "Unknown", "Unknown"
    }

    return
}

Make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant