Syntax of functions,,,https://play.golang.org/p/Ou7esJnAkv

https://play.golang.org/p/Ou7esJnAkv

In this code, can someone tell me:
What is the (r receiver)
What is the identifier(parameters) (return(s)) { … }
What are the (parameters)
What are the(return(s))

In https://play.golang.org/p/dpINmrlSsQ
is “James” the argument?
Are there others?

In https://play.golang.org/p/yY03ihVnkUF
do you have to use the word “return” in order for there to be a return or are there other ways to make that happen?

Its commented out, therefore its nothing but whitespace in that code.

Anything that names a thing is an identifier.

L1: main
L7: main
L13: foo
L14: fmt, Println

The only parameter I see in that code is "hello from foo".

No function in the code does return something.

Yes, "James" is the argument to the functionbar` called in L9.

Yes. You should be able to recognize them on your own.

Yes

Not in go.

1 Like

Don’t know what that means.

The only parameter I see in that code is "hello from foo" .
Thanks. This is helpful.

Yes. You should be able to recognize them on your own.

I’m trying to distinguish arguments from parameters. Here is some information that I have been given:

know the difference between parameters and arguments

  • we define our func with parameters (if any)
  • we call our func and pass in arguments (in any)

Call: specify how many arguments I pass in
When you define a function, it’s called a parameter
We’re going to pass in an argument : bar(James)

From my limited understanding, it appears that
“func foo() {
fmt.Println(“hello from foo”)”

is defining the function. So, you just helped me with this, ("hello from foo) is a parameter;

Whereas “James” is an argument because “we call our func and pass in arguments”.

So I don’t know what other arguments there are.

Some of this I’m getting by deduction, because I don’t have a clear definition for “pass” and “call”.
I studied what the language specification says, but much of it is beyond my understanding. I still study it though as time permits, and it does help me

cherilexvold1974:

I forgot to mention, thanks for the information about returns. Very helpful.

Yes, there is a distinction made between parameters and arguments, but that distinction is… well… Depending on the source those words are used that way you describe it here, and in others they are exchanged.

Even my professor didn’t made the disitinction, because he said, thats more confusing than not to do, and usually its clear from the context if you are talking about those in the function definition or application.

Therefore I use those words synonymously.

Though, if we apply your definition from above, then in

func foo(bar string) {
  fmt.Println(bar)
}

Then the bar in the first line is a parameter of foo, while the bar in the second line is used as an argument in the application of fmt.Println.

After your definition a parameter can never have a concrete value.

1 Like

Very interesting. Thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.