Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible in Go to call a function with named arguments? [duplicate]

I want to call a function in Go, and attach to the argument values the argument names

func sum(a int, b int) int {
  return a + b
}

func main() {
  result := sum(a=4, b=5) // result == 9
}

Is it possible?

like image 937
Netanel.R Avatar asked May 30 '19 07:05

Netanel.R


People also ask

Does Golang have named arguments?

Go does not have named arguments. You can use structs as a workaround.

Is it possible to use arguments in functions?

You can use arguments.length to count how many arguments the function was called with. If you instead want to count how many parameters a function is declared to accept, inspect that function's length property.

How can we pass arguments in function calling?

Arguments are Passed by Value The parameters, in a function call, are the function's arguments. JavaScript arguments are passed by value: The function only gets to know the values, not the argument's locations. If a function changes an argument's value, it does not change the parameter's original value.


1 Answers

There is no such thing like named arguments in go

like image 103
Philidor Avatar answered Nov 03 '22 00:11

Philidor