Function prototype: Difference between revisions
Content deleted Content added
No edit summary |
Go solution |
||
Line 236: | Line 236: | ||
member OptionalArgs : ?x:int * ?y:int -> int |
member OptionalArgs : ?x:int * ?y:int -> int |
||
end</lang> |
end</lang> |
||
=={{header|Go}}== |
|||
While the language specification does not use the word prototype it states, "A function declaration may omit the body. Such a declaration provides the signature for a function implemented outside Go, such as an assembly routine." This is the closest analogy to a C (e.g.) prototype. |
|||
Function declarations whether with a body or without must be "top level" declarations, that is, after the package clause and outside of any other function. Examples of function delarations without bodies are, |
|||
<lang go>func a() // function with no arguments |
|||
func b(x, y int) // function with two arguments |
|||
func c(...int) // varargs are called "variadic parameters" in Go.</lang> |
|||
Go does not directly support optional or named parameters and does not have any concept of procedures or subroutines as distinct from functions. |
|||
Otherwise, Go does have the concept of a function signature which includes parameters and return values. Go is strongly typed and functions are first class objects so function signatures are used in a variety of ways. These might be considered distinct from the concept of function prototype. |
|||
=={{header|J}}== |
=={{header|J}}== |