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

잔글 (Jmnote님이 Go Fibonacci Closure 문서를 Go 클로저 피보나치 예시 문서로 이동했습니다)
(같은 사용자의 중간 판 2개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;Go Fibonacci Closure
;Go Fibonacci Closure
;Go 클로저 피보나치 예시


<syntaxhighlight lang='go' run>
<syntaxhighlight lang='go' run>
23번째 줄: 24번째 줄:
}
}
</syntaxhighlight>
</syntaxhighlight>
==같이 보기==
* [[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 }}