June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
20
Task/Named-parameters/Go/named-parameters.go
Normal file
20
Task/Named-parameters/Go/named-parameters.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type params struct {x, y, z int}
|
||||
|
||||
func myFunc(p params) int {
|
||||
return p.x + p.y + p.z
|
||||
}
|
||||
|
||||
func main() {
|
||||
r := myFunc(params{x: 1, y: 2, z: 3}) // all fields, same order
|
||||
fmt.Println("r =", r)
|
||||
s := myFunc(params{z: 3, y: 2, x: 1}) // all fields, different order
|
||||
fmt.Println("s =", s)
|
||||
t := myFunc(params{y: 2}) // only one field, others set to zero
|
||||
fmt.Println("t =", t)
|
||||
}
|
||||
|
|
@ -3,3 +3,9 @@ sub funkshun ($a, $b?, :$c = 15, :$d, *@e, *%f) {
|
|||
say join ' ', @e;
|
||||
say join ' ', keys %f;
|
||||
}
|
||||
|
||||
# this particularly thorny call:
|
||||
|
||||
funkshun
|
||||
'Alfa', k1 => 'v1', c => 'Charlie', 'Bravo', 'e1',
|
||||
d => 'Delta', 'e2', k2 => 'v2';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue