Jump to content

Call a function: Difference between revisions

Line 1,875:
i = len(list)</lang>
* Go has no subroutines, just functions and methods.
* Go arguments are passed by value or by reference
 
::As with C, a pointer can be used to achieve the effect of reference passing. (Like pointers, slice arguments have their contents passed by reference, it's the slice header that is passed by value).
* Go arguments are passed by value.
::As with C, a pointer can be used to achieve the effect of reference passing. (Like pointers, slice arguments have their contents passed by reference, it's the slice header that is passed by value).
* Go arguments are passed by value or by reference
<lang go>package main
 
Line 1,900 ⟶ 1,899:
fmt.Println("pointer:", &i) // prt pointer: 0xc0000140b8
}</lang>
* Partial applicationand Currying is not directly supported.
<lang go>package main
 
import "fmt"
 
func mkAdd(a int) func(int) int {
return func(b int) int {
return a + b
}
}
func sum(x, y int) int {
return x + y
}
 
func partialSum(x int) func(int) int {
return func(y int) int {
return sum(x, y)
}
}
func main() {
// Is partial application possible and how
add2 := mkAdd(2)
add3 := mkAdd(3)
fmt.Println(add2(5), add3(6)) // prt 7 9
// Currying functions in go
partial := partialSum(13)
fmt.Println(partial(5)) //prt 18
}</lang>
::However something similar can be done, see [[Partial function application#Go]]
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.