{"id":2965,"date":"2013-08-27T13:12:24","date_gmt":"2013-08-27T04:12:24","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=2965"},"modified":"2013-08-27T13:12:24","modified_gmt":"2013-08-27T04:12:24","slug":"5-2-ifthenelse","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/2965","title":{"rendered":"5.2. if\/then\/else"},"content":{"rendered":"<p><a href=\"https:\/\/peta.okechan.net\/blog\/archives\/2836\" title=\"LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\">LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u65e5\u672c\u8a9e\u8a33<\/a><br \/>\n\u7b2c5\u7ae0 \u4e07\u83ef\u93e1: \u8a00\u8a9e\u306e\u62e1\u5f35: \u5236\u5fa1\u30d5\u30ed\u30fc<br \/>\n<a href=\"http:\/\/llvm.org\/docs\/tutorial\/LangImpl05.html#if-then-else\" target=\"_blank\">\u7b2c2\u7bc0 if\/then\/else<\/a><\/p>\n<p>if\/then\/else\u306e\u30b5\u30dd\u30fc\u30c8\u306b\u3088\u308b\u4e07\u83ef\u93e1\u306e\u62e1\u5f35\u306f\u3001\u5b9f\u306b\u7c21\u5358\u3067\u3042\u308b\u3002<br \/>\n\u57fa\u672c\u7684\u306b\u306f\u3001\u5b57\u53e5\u89e3\u6790\u5668\u3068\u69cb\u6587\u89e3\u6790\u5668\u3068AST\u3068LLVM\u30b3\u30fc\u30c9\u751f\u6210\u90e8\u5206\u306b\u5bfe\u3057\u3066\u3001\u3053\u308c\u3089\u306e\u65b0\u3057\u3044\u30b3\u30f3\u30bb\u30d7\u30c8\u306b\u5bfe\u3059\u308b\u30b5\u30dd\u30fc\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u5fc5\u8981\u3067\u3042\u308b\u3002<br \/>\n\u3053\u306e\u5b9f\u4f8b\u306f\u7d20\u6674\u3089\u3057\u3044\u3082\u306e\u3067\u3042\u308b\u3002<br \/>\n\u306a\u305c\u306a\u3089\u3001\u65b0\u3057\u3044\u30a2\u30a4\u30c7\u30a2\u306b\u3088\u3063\u3066\u8a00\u8a9e\u3092\u5c11\u3057\u305a\u3064\u62e1\u5f35\u3057\u3001\u6642\u9593\u3092\u639b\u3051\u3066\u80b2\u3066\u3066\u3044\u304f\u306e\u304c\u3044\u304b\u306b\u7c21\u5358\u304b\u3092\u793a\u3059\u3082\u306e\u3060\u304b\u3089\u3067\u3042\u308b\u3002<\/p>\n<p>\u3053\u306e\u62e1\u5f35\u3092\u8ffd\u52a0\u3059\u308b\u65b9\u6cd5\u306b\u9032\u3080\u524d\u306b\u3001\u4f55\u304c\u5fc5\u8981\u306a\u306e\u304b\u306b\u3064\u3044\u3066\u8003\u3048\u3066\u307f\u3088\u3046\u3002<br \/>\n\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u66f8\u3051\u308b\u3088\u3046\u306b\u3057\u305f\u3044\u3068\u3044\u3046\u306e\u304c\u57fa\u672c\u7684\u306a\u8003\u3048\u3067\u3042\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">def fib(x)\r\n  if x &lt; 3 then\r\n    1\r\n  else\r\n    fib(x-1)+fib(x-2);<\/pre>\n<p>\u4e07\u83ef\u93e1\u3067\u306f\u3001\u5404\u69cb\u6210\u7269\u306f\u5f0f\u3067\u3042\u308b\u3002<br \/>\n\u6587\u306f\u5b58\u5728\u3057\u306a\u3044\u3002<br \/>\n\u306a\u306e\u3067\u3001if\/then\/else\u5f0f\u306f\u4f55\u3089\u304b\u306e\u623b\u308a\u5024\u3092\u8fd4\u3059\u5fc5\u8981\u304c\u3042\u3042\u308b\u3002<br \/>\n\u5927\u90e8\u5206\u306f\u95a2\u6570\u306e\u5f62\u3092\u4f7f\u3063\u3066\u308b\u306e\u3067\u3001\u305d\u306e\u6761\u4ef6\u6587\u3092\u8a55\u4fa1\u3057\u3001\u305d\u3057\u3066\u6761\u4ef6\u304c\u3069\u3046\u89e3\u6c7a\u3055\u308c\u305f\u304b\u306b\u57fa\u3065\u304d\u201dthen&#8221;\u304b&#8221;else&#8221;\u306e\u5024\u3092\u623b\u3059\u3088\u3046\u306b\u3059\u308b\u3002<br \/>\n\u3053\u308c\u306f\u3001C\u306e&#8221;?:&#8221;\u5f0f\u306b\u304b\u306a\u308a\u4f3c\u3066\u3044\u308b\u3002<br \/>\n<em>\u8a33\u6ce8: ?:\u306fC\u306e\u4e09\u9805\u6f14\u7b97\u5b50\u306e\u4e8b\u3002<\/em><\/p>\n<p>if\/then\/else\u5f0f\u306e\u52d5\u4f5c\u3068\u3057\u3066\u306f\u3001\u6761\u4ef6\u5f0f\u306b\u304a\u3044\u3066\u30010.0\u3068\u7b49\u3057\u3044\u5024\u3092\u771f\u507d\u5024\u306b\u304a\u3051\u308bfalse\u3068\u3057\u3066\u8a55\u4fa1\u3057\u3001\u305d\u308c\u4ee5\u5916\u3092true\u3068\u3057\u3066\u8a55\u4fa1\u3059\u308b\u3002<br \/>\n\u3082\u3057\u6761\u4ef6\u304ctrue\u306a\u3089\u3001\u6700\u521d\u306e\u526f\u6b21\u5f0f\uff08then\u306e\u5f0f\uff09\u304c\u8a55\u4fa1\u3055\u308c\u305d\u306e\u7d50\u679c\u304c\u8fd4\u308b\u3002<br \/>\n\u3082\u3057\u6761\u4ef6\u304cfalse\u306a\u3089\u30012\u756a\u76ee\u306e\u526f\u6b21\u5f0f\uff08else\u306e\u5f0f\uff09\u304c\u8a55\u4fa1\u3055\u308c\u305d\u306e\u7d50\u679c\u304c\u8fd4\u308b\u3002<br \/>\n\u4e07\u83ef\u93e1\u306f\u526f\u4f5c\u7528\u3092\u8a31\u5bb9\u3059\u308b\u306e\u3067\u3001\u3053\u306e\u632f\u308b\u821e\u3044\u306f\u660e\u78ba\u306b\u5b9a\u7fa9\u3059\u308b\u305f\u3081\u306b\u91cd\u8981\u3067\u3042\u308b\u3002\uff08Since Kaleidoscope allows side-effects, this behavior is important to nail down.\uff09<br \/>\n<em>\u8a33\u6ce8: \u526f\u4f5c\u7528\u3092\u8a31\u5bb9\u3057\u306a\u3044\u306a\u3089\u3070\u3001then\u3068else\u306e\u4e21\u65b9\u306e\u5f0f\u3092\u5b9f\u884c\u3057\u3066\u5fc5\u8981\u306a\u307b\u3046\u306e\u5024\u3060\u3051\u3092\u8fd4\u3059\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u3082\u51fa\u6765\u308b\u304c\u3001\u526f\u4f5c\u7528\u3092\u8a31\u5bb9\u3059\u308b\u306e\u3067\u305d\u3046\u306f\u51fa\u6765\u306a\u3044\u3068\u3044\u3046\u610f\u5473\u304b\u3068\u601d\u3046\u3002<\/em><\/p>\n<p>\u3053\u308c\u3067\u3001\u6211\u3005\u304c\u6b32\u3057\u3044\u7269\u306f\u306f\u3063\u304d\u308a\u3057\u305f\u3002<br \/>\n\u3053\u308c\u3092\u500b\u3005\u306e\u69cb\u6210\u90e8\u54c1\u306b\u5206\u89e3\u3057\u3066\u307f\u3088\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p><a href=\"https:\/\/peta.okechan.net\/blog\/archives\/2836\" title=\"LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\">LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u65e5\u672c\u8a9e\u8a33<\/a><br \/>\n\u7b2c5\u7ae0 \u4e07\u83ef\u93e1: \u8a00\u8a9e\u306e\u62e1\u5f35: \u5236\u5fa1\u30d5\u30ed\u30fc<br \/>\n<a href=\"http:\/\/llvm.org\/docs\/tutorial\/LangImpl05.html#if-then-else\" target=\"_blank\">\u7b2c2\u7bc0 if\/then\/else<\/a><\/p>\n<p>if\/then\/else\u306e\u30b5\u30dd\u30fc\u30c8\u306b\u3088\u308b\u4e07\u83ef\u93e1\u306e\u62e1\u5f35\u306f\u3001\u5b9f\u306b\u7c21\u5358\u3067\u3042\u308b\u3002<br \/>\n\u57fa\u672c\u7684\u306b\u306f\u3001\u5b57\u53e5\u89e3\u6790\u5668\u3068\u69cb\u6587\u89e3\u6790\u5668\u3068AST\u3068LLVM\u30b3\u30fc\u30c9\u751f\u6210\u90e8\u5206\u306b\u5bfe\u3057\u3066\u3001\u3053\u308c\u3089\u306e\u65b0\u3057\u3044\u30b3\u30f3\u30bb\u30d7\u30c8\u306b\u5bfe\u3059\u308b\u30b5\u30dd\u30fc\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u5fc5\u8981\u3067\u3042\u308b\u3002<br \/>\n\u3053\u306e\u5b9f\u4f8b\u306f\u7d20\u6674\u3089\u3057\u3044\u3082\u306e\u3067\u3042\u308b\u3002<br \/>\n\u306a\u305c\u306a\u3089\u3001\u65b0\u3057\u3044\u30a2\u30a4\u30c7\u30a2\u306b\u3088\u3063\u3066\u8a00\u8a9e\u3092\u5c11\u3057\u305a\u3064\u62e1\u5f35\u3057\u3001\u6642\u9593\u3092\u639b\u3051\u3066\u80b2\u3066\u3066\u3044\u304f\u306e\u304c\u3044\u304b\u306b\u7c21\u5358\u304b\u3092\u793a\u3059\u3082\u306e\u3060\u304b\u3089\u3067\u3042\u308b\u3002<\/p>\n<p>\u3053\u306e\u62e1\u5f35\u3092\u8ffd\u52a0\u3059\u308b\u65b9\u6cd5\u306b\u9032\u3080\u524d\u306b\u3001\u4f55\u304c\u5fc5\u8981\u306a\u306e\u304b\u306b\u3064\u3044\u3066\u8003\u3048\u3066\u307f\u3088\u3046\u3002<br \/>\n\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u66f8\u3051\u308b\u3088\u3046\u306b\u3057\u305f\u3044\u3068\u3044\u3046\u306e\u304c\u57fa\u672c\u7684\u306a\u8003\u3048\u3067\u3042\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">def fib(x)\r\n  if x &lt; 3 then\r\n    1\r\n  else\r\n    fib(x-1)+fib(x-2);<\/pre>\n<p>\u4e07\u83ef\u93e1\u3067\u306f\u3001\u5404\u69cb\u6210\u7269\u306f\u5f0f\u3067\u3042\u308b\u3002<br \/>\n\u6587\u306f\u5b58\u5728\u3057\u306a\u3044\u3002<br \/>\n\u306a\u306e\u3067\u3001if\/then\/else\u5f0f\u306f\u4f55\u3089\u304b\u306e\u623b\u308a\u5024\u3092\u8fd4\u3059\u5fc5\u8981\u304c\u3042\u3042\u308b\u3002<br \/>\n\u5927\u90e8\u5206\u306f\u95a2\u6570\u306e\u5f62\u3092\u4f7f\u3063\u3066\u308b\u306e\u3067\u3001\u305d\u306e\u6761\u4ef6\u6587\u3092\u8a55\u4fa1\u3057\u3001\u305d\u3057\u3066\u6761\u4ef6\u304c\u3069\u3046\u89e3\u6c7a\u3055\u308c\u305f\u304b\u306b\u57fa\u3065\u304d\u201dthen&#8221;\u304b&#8221;else&#8221;\u306e\u5024\u3092\u623b\u3059\u3088\u3046\u306b\u3059\u308b\u3002<br \/>\n\u3053\u308c\u306f\u3001C\u306e&#8221;?:&#8221;\u5f0f\u306b\u304b\u306a\u308a\u4f3c\u3066\u3044\u308b\u3002<br \/>\n<em>\u8a33\u6ce8: ?:\u306fC\u306e\u4e09\u9805\u6f14\u7b97\u5b50\u306e\u4e8b\u3002<\/em><\/p>\n<p>if\/then\/else\u5f0f\u306e\u52d5\u4f5c\u3068\u3057\u3066\u306f\u3001\u6761\u4ef6\u5f0f\u306b\u304a\u3044\u3066\u30010.0\u3068\u7b49\u3057\u3044\u5024\u3092\u771f\u507d\u5024\u306b\u304a\u3051\u308bfalse\u3068\u3057\u3066\u8a55\u4fa1\u3057\u3001\u305d\u308c\u4ee5\u5916\u3092true\u3068\u3057\u3066\u8a55\u4fa1\u3059\u308b\u3002<br \/>\n\u3082\u3057\u6761\u4ef6\u304ctrue\u306a\u3089\u3001\u6700\u521d\u306e\u526f\u6b21\u5f0f\uff08then\u306e\u5f0f\uff09\u304c\u8a55\u4fa1\u3055\u308c\u305d\u306e\u7d50\u679c\u304c\u8fd4\u308b\u3002<br \/>\n\u3082\u3057\u6761\u4ef6\u304cfalse\u306a\u3089\u30012\u756a\u76ee\u306e\u526f\u6b21\u5f0f\uff08else\u306e\u5f0f\uff09\u304c\u8a55\u4fa1\u3055\u308c\u305d\u306e\u7d50\u679c\u304c\u8fd4\u308b\u3002<br \/>\n\u4e07\u83ef\u93e1\u306f\u526f\u4f5c\u7528\u3092\u8a31\u5bb9\u3059\u308b\u306e\u3067\u3001\u3053\u306e\u632f\u308b\u821e\u3044\u306f\u660e\u78ba\u306b\u5b9a\u7fa9\u3059\u308b\u305f\u3081\u306b\u91cd\u8981\u3067\u3042\u308b\u3002\uff08Since Kaleidoscope allows side-effects, this behavior is important to nail down.\uff09<br \/>\n<em>\u8a33\u6ce8: \u526f\u4f5c\u7528\u3092\u8a31\u5bb9\u3057\u306a\u3044\u306a\u3089\u3070\u3001then\u3068else\u306e\u4e21\u65b9\u306e\u5f0f\u3092\u5b9f\u884c\u3057\u3066\u5fc5\u8981\u306a\u307b\u3046\u306e\u5024\u3060\u3051\u3092\u8fd4\u3059\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u3082\u51fa\u6765\u308b\u304c\u3001\u526f\u4f5c\u7528\u3092\u8a31\u5bb9\u3059\u308b\u306e\u3067\u305d\u3046\u306f\u51fa\u6765\u306a\u3044\u3068\u3044\u3046\u610f\u5473\u304b\u3068\u601d\u3046\u3002<\/em><\/p>\n<p>\u3053\u308c\u3067\u3001\u6211\u3005\u304c\u6b32\u3057\u3044\u7269\u306f\u306f\u3063\u304d\u308a\u3057\u305f\u3002<br \/>\n\u3053\u308c\u3092\u500b\u3005\u306e\u69cb\u6210\u90e8\u54c1\u306b\u5206\u89e3\u3057\u3066\u307f\u3088\u3046\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[466,467],"class_list":["post-2965","post","type-post","status-publish","format-standard","hentry","category-tech","tag-kaleidoscope","tag-llvm"],"_links":{"self":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/2965","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/comments?post=2965"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/2965\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=2965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=2965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=2965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}