go-analyzer/tests/test_funcs.txt

34 lines
597 B
Plaintext

package main;
import "fmt";
// анонимные функции
func anon_func() {
// Присваиваем анонимную функцию переменной
square := func(x int) int {
return x * x;
};
fmt.Println(square(5)); // Выведет: 25
}
// замыкания
func intSeq() func() int {
i := 0;
return func() int {
i++;
return i;
};
}
func main() {
nextInt := intSeq();
fmt.Println(nextInt());
fmt.Println(nextInt());
fmt.Println(nextInt());
newInts := intSeq();
fmt.Println(newInts());
}