"Go 클로저 피보나치 예시"의 두 판 사이의 차이

27번째 줄: 27번째 줄:
==같이 보기==
==같이 보기==
* [[Go 클로저]]
* [[Go 클로저]]
* [[Go 재귀]]


==참고==
==참고==

2021년 10월 20일 (수) 13:22 판

1 개요

Go Fibonacci Closure
Go 클로저 피보나치 예시
package main

import "fmt"

// fib returns a function that returns
// successive Fibonacci numbers.
func fib() func() int {
	a, b := 0, 1
	return func() int {
		a, b = b, a+b
		return a
	}
}

func main() {
	f := fib()
	// Function calls are evaluated left-to-right.
	fmt.Println(f(), f(), f(), f(), f())
}

2 같이 보기

3 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}