{"id":1241,"date":"2022-11-25T09:03:02","date_gmt":"2022-11-25T01:03:02","guid":{"rendered":"https:\/\/fdream.net\/blog\/?p=1241"},"modified":"2022-11-25T09:03:02","modified_gmt":"2022-11-25T01:03:02","slug":"go%e6%8c%87%e5%8d%97%e7%bb%83%e4%b9%a04-%e6%96%90%e6%b3%a2%e9%82%a3%e5%a5%91%e9%97%ad%e5%8c%85","status":"publish","type":"post","link":"https:\/\/fdream.net\/blog\/article\/1241","title":{"rendered":"Go\u6307\u5357\u7ec3\u4e604-\u6590\u6ce2\u90a3\u5951\u95ed\u5305"},"content":{"rendered":"\n<p>\u8fd9\u4e2a\u662f<a rel=\"noreferrer noopener\" href=\"https:\/\/go.dev\/tour\/list\" target=\"_blank\">A Tour of Go<\/a>\u8fd9\u4e2a\u6559\u7a0b\u91cc\u9762\u7684\u7b2c\u56db\u4e2a\u7ec3\u4e60\uff0c<a href=\"https:\/\/tour.go-zh.org\/moretypes\/26\" target=\"_blank\" rel=\"noreferrer noopener\">\u539f\u9898<\/a>\u5982\u4e0b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5b9e\u73b0\u4e00\u4e2a\u00a0<code>fibonacci<\/code>\u00a0\u51fd\u6570\uff0c\u5b83\u8fd4\u56de\u4e00\u4e2a\u51fd\u6570\uff08\u95ed\u5305\uff09\uff0c\u8be5\u95ed\u5305\u8fd4\u56de\u4e00\u4e2a<a rel=\"noreferrer noopener\" href=\"https:\/\/zh.wikipedia.org\/wiki\/%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%88%97\" target=\"_blank\">\u6590\u6ce2\u7eb3\u5951\u6570\u5217<\/a>\u00a0`(0, 1, 1, 2, 3, 5, &#8230;)`\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>\u539f\u9898\u4ee3\u7801\u6a21\u677f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ fibonacci is a function that returns\n\/\/ a function that returns an int.\nfunc fibonacci() func() int {\n}\n\nfunc main() {\n\tf := fibonacci()\n\tfor i := 0; i &lt; 10; i++ {\n\t\tfmt.Println(f())\n\t}\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u9898\u9700\u8981<code>fibonacci<\/code>\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u95ed\u5305\u51fd\u6570\uff0c\u8fd9\u4e2a\u95ed\u5305\u51fd\u6570\u9700\u8981\u5f15\u7528\u51fd\u6570\u4f53\u5916\u7684\u53d8\u91cf\uff0c\u5e76\u5bf9\u5176\u8fdb\u884c\u4fee\u6539\uff0c\u4ee5\u4fdd\u5b58\u4e2d\u95f4\u7ed3\u679c\u2014\u2014\u8be5\u6570\u5217\u7684\u6700\u65b0\u7684\u4e24\u4e2a\u503c\u3002\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ \u8fd4\u56de\u4e00\u4e2a\u201c\u8fd4\u56deint\u7684\u51fd\u6570\u201d\nfunc fibonacci() func() int {\n\tx, y := 1, 0  \/\/ \u521d\u59cb\u503c\n\treturn func() int {\n\t\t\/\/ \u6ce8\u610f\uff1a\u8fd9\u91cc\u9700\u8981\u4ece0\u5f00\u59cb\u8fd4\u56de\n\t\tx, y = y, x+y\n\t\treturn x\n\t}\n}\n\nfunc main() {\n\tf := fibonacci()\n\tfor i := 0; i &lt; 10; i++ {\n\t\tfmt.Println(f())\n\t}\n}\n<\/code><\/pre>\n\n\n\n<p>\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0\n1\n1\n2\n3\n5\n8\n13\n21\n34<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e2a\u662fA Tour of Go\u8fd9\u4e2a\u6559\u7a0b\u91cc\u9762\u7684\u7b2c\u56db\u4e2a\u7ec3\u4e60\uff0c\u539f\u9898\u5982\u4e0b\uff1a \u5b9e\u73b0\u4e00\u4e2a\u00a0fibonacci\u00a0\u51fd\u6570\uff0c\u5b83\u8fd4\u56de\u4e00\u4e2a\u51fd\u6570\uff08\u95ed\u5305\uff09\uff0c\u8be5\u95ed\u5305\u8fd4\u56de\u4e00\u4e2a\u6590\u6ce2\u7eb3\u5951\u6570\u5217\u00a0`(0, 1, 1, 2, 3, 5, &#8230;)`\u3002 \u539f\u9898\u4ee3\u7801\u6a21\u677f\u5982\u4e0b\uff1a \u8fd9\u9898\u9700\u8981fibonacci\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u95ed\u5305\u51fd\u6570\uff0c\u8fd9\u4e2a\u95ed\u5305\u51fd\u6570\u9700\u8981\u5f15\u7528\u51fd\u6570\u4f53\u5916\u7684\u53d8\u91cf\uff0c\u5e76\u5bf9\u5176\u8fdb\u884c\u4fee\u6539\uff0c\u4ee5\u4fdd\u5b58\u4e2d\u95f4\u7ed3\u679c\u2014\u2014\u8be5\u6570\u5217\u7684\u6700\u65b0\u7684\u4e24\u4e2a\u503c\u3002\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\uff1a \u8f93\u51fa\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[374],"class_list":["post-1241","post","type-post","status-publish","format-standard","hentry","category-coding","tag-go"],"views":310,"_links":{"self":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/1241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/comments?post=1241"}],"version-history":[{"count":0,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/1241\/revisions"}],"wp:attachment":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/media?parent=1241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/categories?post=1241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/tags?post=1241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}