Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
11
Task/Call-a-function/Go/call-a-function-1.go
Normal file
11
Task/Call-a-function/Go/call-a-function-1.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import (
|
||||
"image"
|
||||
"image/gif"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
func f() (int, float64) { return 0, 0 }
|
||||
func g(int, float64) int { return 0 }
|
||||
func h(string, ...int) {}
|
||||
9
Task/Call-a-function/Go/call-a-function-2.go
Normal file
9
Task/Call-a-function/Go/call-a-function-2.go
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
f()
|
||||
g(1, 2.0)
|
||||
// If f() is defined to return exactly the number and type of
|
||||
// arguments that g() accepts than they can be used in place:
|
||||
g(f())
|
||||
// But only without other arguments, this won't compile:
|
||||
//h("fail", f())
|
||||
// But this will:
|
||||
g(g(1, 2.0), 3.0)
|
||||
8
Task/Call-a-function/Go/call-a-function-3.go
Normal file
8
Task/Call-a-function/Go/call-a-function-3.go
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
h("ex1")
|
||||
h("ex2", 1, 2)
|
||||
h("ex3", 1, 2, 3, 4)
|
||||
// such functions can also be called by expanding a slice:
|
||||
list := []int{1,2,3,4}
|
||||
h("ex4", list...)
|
||||
// but again, not mixed with other arguments, this won't compile:
|
||||
//h("fail", 2, list...)
|
||||
1
Task/Call-a-function/Go/call-a-function-4.go
Normal file
1
Task/Call-a-function/Go/call-a-function-4.go
Normal file
|
|
@ -0,0 +1 @@
|
|||
gif.Encode(ioutil.Discard, image.Black, &gif.Options{NumColors: 16})
|
||||
1
Task/Call-a-function/Go/call-a-function-5.go
Normal file
1
Task/Call-a-function/Go/call-a-function-5.go
Normal file
|
|
@ -0,0 +1 @@
|
|||
if 2*g(1, 3.0)+4 > 0 {}
|
||||
9
Task/Call-a-function/Go/call-a-function-6.go
Normal file
9
Task/Call-a-function/Go/call-a-function-6.go
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fn := func(r rune) rune {
|
||||
if unicode.IsSpace(r) {
|
||||
return -1
|
||||
}
|
||||
return r
|
||||
}
|
||||
strings.Map(fn, "Spaces removed")
|
||||
strings.Map(unicode.ToLower, "Test")
|
||||
strings.Map(func(r rune) rune { return r + 1 }, "shift")
|
||||
4
Task/Call-a-function/Go/call-a-function-7.go
Normal file
4
Task/Call-a-function/Go/call-a-function-7.go
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
a, b := f() // multivalue return
|
||||
_, c := f() // only some of a multivalue return
|
||||
d := g(a, c) // single return value
|
||||
e, i := g(d, b), g(d, 2) // multiple assignment
|
||||
2
Task/Call-a-function/Go/call-a-function-8.go
Normal file
2
Task/Call-a-function/Go/call-a-function-8.go
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
list = append(list, a, d, e, i)
|
||||
i = len(list)
|
||||
Loading…
Add table
Add a link
Reference in a new issue