60 lines
1.0 KiB
Plaintext
60 lines
1.0 KiB
Plaintext
package main;
|
|
|
|
import "fmt";
|
|
|
|
|
|
func ujas() (func() func() func() int, int, string) {
|
|
return func() func() func() int {
|
|
return func() func() int {
|
|
return func() int {
|
|
return 0;
|
|
};
|
|
};
|
|
}, 1, "hello world";
|
|
}
|
|
|
|
func A(x, y int) {
|
|
}
|
|
|
|
func B(x, y int) () {
|
|
}
|
|
|
|
func C(x, y int) int {
|
|
}
|
|
|
|
func D(x, y int) (int, string) {
|
|
}
|
|
|
|
func E(x, y int) (z, f, u int, a string) {
|
|
}
|
|
|
|
// анонимные функции
|
|
func anon_func(a,b,c,d string, a int) {
|
|
// Присваиваем анонимную функцию переменной
|
|
square := func(x, y int) int {
|
|
return x * y;
|
|
};
|
|
|
|
fmt.Println(square(5, 5)); // Выведет: 25
|
|
}
|
|
|
|
// замыкания
|
|
func intSeq() func() int {
|
|
i := 0;
|
|
return func() int {
|
|
i++;
|
|
return i;
|
|
};
|
|
}
|
|
|
|
func main() {
|
|
|
|
nextInt := intSeq(intSeq(), intSeq(), intSeq(), intSeq(intSeq())); // рекурсия
|
|
|
|
fmt.Println(nextInt());
|
|
fmt.Println(nextInt());
|
|
fmt.Println(nextInt());
|
|
|
|
newInts := intSeq();
|
|
fmt.Println(newInts());
|
|
} |