{"id":476419,"date":"2023-08-09T07:29:55","date_gmt":"2023-08-09T07:29:55","guid":{"rendered":""},"modified":"2023-09-05T11:12:43","modified_gmt":"2023-09-05T11:12:43","slug":"continuation-passing-style-cps","status":"publish","type":"wiki","link":"https:\/\/oneproxy.pro\/cn\/wiki\/continuation-passing-style-cps\/","title":{"rendered":"\u8fde\u7eed\u4f20\u9012\u98ce\u683c (CPS)"},"content":{"rendered":"<p>\u5ef6\u7eed\u4f20\u9012\u98ce\u683c (CPS) \u662f\u4e00\u79cd\u5904\u7406\u8ba1\u7b97\u673a\u7f16\u7a0b\u4e2d\u7684\u63a7\u5236\u6d41\u7684\u65b9\u6cd5\uff0c\u6d89\u53ca\u901a\u8fc7\u51fd\u6570\u53c2\u6570\u663e\u5f0f\u4f20\u9012\u63a7\u5236\u3002<\/p>\n<h2>\u8fde\u7eed\u4f20\u7403\u98ce\u683c\uff08CPS\uff09\u7684\u6f14\u53d8<\/h2>\n<p>\u5ef6\u7eed\u4f20\u9012\u98ce\u683c\u7684\u8d77\u6e90\u53ef\u4ee5\u8ffd\u6eaf\u5230\u7406\u8bba\u8ba1\u7b97\u673a\u79d1\u5b66\u7684\u53d1\u5c55\uff0c\u800c\u5ef6\u7eed\u672c\u8eab\u7684\u6982\u5ff5\u5219\u6e90\u4e8e lambda \u6f14\u7b97\u3002\u8ba1\u7b97\u673a\u79d1\u5b66\u5bb6 Christopher Strachey \u5728 20 \u4e16\u7eaa 60 \u5e74\u4ee3\u9996\u6b21\u660e\u786e\u63d0\u53ca\u201c\u5ef6\u7eed\u4f20\u9012\u98ce\u683c\u201d\u5e76\u5c06\u5176\u7528\u4e8e\u5b9e\u8df5\u3002\u6b63\u662f\u5728\u8fd9\u4e00\u65f6\u671f\uff0c\u4ed6\u548c\u4ed6\u7684\u540c\u4e8b\u4eec\u6b63\u5728\u63a2\u7d22\u6307\u79f0\u8bed\u4e49\uff0c\u8fd9\u662f\u4e00\u79cd\u5b9a\u4e49\u7f16\u7a0b\u8bed\u8a00\u542b\u4e49\u7684\u6846\u67b6\u3002<\/p>\n<h2>\u5c55\u5f00\u8fde\u7eed\u4f20\u9012\u98ce\u683c (CPS)<\/h2>\n<p>\u5ef6\u7eed\u4f20\u9012\u6837\u5f0f (CPS) \u662f\u4e00\u79cd\u6d89\u53ca\u663e\u5f0f\u4f7f\u7528\u5ef6\u7eed\u7684\u7a0b\u5e8f\u7ec4\u7ec7\u5f62\u5f0f\u3002\u5ef6\u7eed\u662f\u8ba1\u7b97\u673a\u7a0b\u5e8f\u5728\u67d0\u4e00\u65f6\u95f4\u70b9\u7684\u72b6\u6001\u8868\u793a\uff0c\u5305\u62ec\u8c03\u7528\u5806\u6808\u548c\u53d8\u91cf\u7684\u503c\u3002<\/p>\n<p>\u5728 CPS \u4e2d\uff0c\u6bcf\u4e2a\u51fd\u6570\u90fd\u4f1a\u6536\u5230\u4e00\u4e2a\u989d\u5916\u7684\u53c2\u6570\uff0c\u901a\u5e38\u540d\u4e3a\u201ccont\u201d\u6216\u201ck\u201d\uff0c\u5b83\u8868\u793a\u7a0b\u5e8f\u7684\u5ef6\u7eed\u6027\u2014\u2014\u51fd\u6570\u5b8c\u6210\u8ba1\u7b97\u540e\u5e94\u8be5\u53d1\u751f\u4ec0\u4e48\u3002\u5f53\u51fd\u6570\u8ba1\u7b97\u51fa\u7ed3\u679c\u65f6\uff0c\u5b83\u4f1a\u901a\u8fc7\u5c06\u5176\u4f20\u9012\u7ed9\u5ef6\u7eed\u6027\u6765\u201c\u8fd4\u56de\u201d\u8be5\u7ed3\u679c\uff0c\u800c\u4e0d\u662f\u4ee5\u901a\u5e38\u7684\u65b9\u5f0f\u8fd4\u56de\u5b83\u3002<\/p>\n<p>\u8fd9\u4e2a\u6982\u5ff5\u53ef\u4ee5\u88ab\u770b\u4f5c\u662f\u4e00\u79cd\u4f7f\u63a7\u5236\u6d41\u663e\u5f0f\u5316\u7684\u65b9\u6cd5\uff1aCPS \u51fd\u6570\u5728\u5b8c\u6210\u65f6\u4e0d\u662f\u9690\u5f0f\u5730\u5c06\u63a7\u5236\u6743\u4f20\u9012\u7ed9\u8c03\u7528\u8005\uff0c\u800c\u662f\u901a\u8fc7\u8c03\u7528\u5ef6\u7eed\u6765\u4f20\u9012\u63a7\u5236\u6743\u3002<\/p>\n<h2>\u8fde\u7eed\u4f20\u7403\u98ce\u683c\uff08CPS\uff09\u7684\u7ed3\u6784<\/h2>\n<p>\u5728\u4f20\u7edf\u7684\u51fd\u6570\u8c03\u7528\u7ea6\u5b9a\u4e2d\uff0c\u5f53\u4e00\u4e2a\u51fd\u6570\u88ab\u8c03\u7528\u65f6\uff0c\u5b83\u4f1a\u6267\u884c\u5e76\u5c06\u63a7\u5236\u6743\u8fde\u540c\u8fd4\u56de\u503c\u4e00\u8d77\u8fd4\u56de\u7ed9\u8c03\u7528\u8005\u3002\u7136\u800c\uff0c\u5728\u5ef6\u7eed\u4f20\u9012\u6837\u5f0f\u4e2d\uff0c\u63a7\u5236\u6743\u662f\u901a\u8fc7\u51fd\u6570\u53c2\u6570\u663e\u5f0f\u4f20\u9012\u7684\uff0c\u8fd9\u901a\u5e38\u88ab\u79f0\u4e3a\u201c\u5ef6\u7eed\u201d\u3002<\/p>\n<p>\u5ef6\u7eed\u8868\u793a\u5269\u4f59\u7684\u8ba1\u7b97\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u51fd\u6570\u63a5\u6536\u5230\u5ef6\u7eed\u65f6\uff0c\u5b83\u4f1a\u6267\u884c\u4e00\u4e9b\u64cd\u4f5c\uff0c\u7136\u540e\u5c06\u7ed3\u679c\u4f20\u9012\u7ed9\u63a5\u6536\u5230\u7684\u5ef6\u7eed\u3002\u56e0\u6b64\uff0c\u5728\u5ef6\u7eed\u4f20\u9012\u6837\u5f0f\u4e2d\uff0c\u6c38\u8fdc\u4e0d\u4f1a\u9690\u5f0f\u6267\u884c\u8fd4\u56de\u3002<\/p>\n<p>\u4f2a\u8bed\u8a00\u4e2d\u7684\u5178\u578b CPS \u51fd\u6570\u53ef\u80fd\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><div class=\"bg-black rounded-md mb-4\"><div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><span>CSS<\/span><button class=\"flex ml-auto gap-2\"><svg stroke=\"currentColor\" fill=\"none\" stroke-width=\"2\" viewbox=\"0 0 24 24\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"h-4 w-4\" height=\"1em\" width=\"1em\" ><path d=\"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2\"><\/path><rect x=\"8\" y=\"2\" width=\"8\" height=\"4\" rx=\"1\" ry=\"1\"><\/rect><\/svg>\u590d\u5236\u4ee3\u7801<\/button><\/div><div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-css\" data-no-translation=\"\">function add(<span class=\"hljs-selector-tag\">a<\/span>, <span class=\"hljs-selector-tag\">b<\/span>, continuation) {\n    result = <span class=\"hljs-selector-tag\">a<\/span> + <span class=\"hljs-selector-tag\">b<\/span>;\n    continuation(result);\n}\n<\/code><\/div><\/div><\/pre>\n<p>\u8fd9\u4e2a\u201cadd\u201d\u51fd\u6570\u6267\u884c\u52a0\u6cd5\u8fd0\u7b97\uff0c\u7136\u540e\u5c06\u7ed3\u679c\u4f20\u9012\u7ed9\u5ef6\u7eed\u3002<\/p>\n<h2>\u8fde\u7eed\u4f20\u7403\u98ce\u683c (CPS) \u7684\u4e3b\u8981\u7279\u70b9<\/h2>\n<ol>\n<li>\n<p><strong>\u663e\u5f0f\u63a7\u5236\u6d41<\/strong>\uff1a\u5728 CPS \u4e2d\uff0c\u63a7\u5236\u6d41\u662f\u660e\u786e\u7684\u3002\u6ca1\u6709\u9690\u85cf\u7684\u5806\u6808\u8ddf\u8e2a\uff0c\u60a8\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u6e05\u695a\u5730\u770b\u5230\u6267\u884c\u987a\u5e8f\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u7075\u6d3b\u6027<\/strong>\uff1a\u7531\u4e8e CPS \u5c06\u8ba1\u7b97\u4e0e\u63a7\u5236\u6d41\u5206\u79bb\uff0c\u56e0\u6b64\u5b83\u4e3a\u64cd\u7eb5\u63a7\u5236\u6d41\u63d0\u4f9b\u4e86\u66f4\u5927\u7684\u7075\u6d3b\u6027\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u975e\u963b\u585e\u64cd\u4f5c<\/strong>\uff1aCPS \u5728\u7ba1\u7406\u975e\u963b\u585e\u6216\u5f02\u6b65\u64cd\u4f5c\u65b9\u9762\u975e\u5e38\u6709\u7528\u3002\u5b83\u53ef\u7528\u4e8e\u907f\u514d\u56de\u8c03\u5730\u72f1\u5e76\u7ba1\u7406\u975e\u963b\u585e\u4ee3\u7801\u4e2d\u7684\u590d\u6742\u63a7\u5236\u6d41\u573a\u666f\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u5c3e\u90e8\u8c03\u7528\u4f18\u5316<\/strong>\uff1a\u652f\u6301\u5c3e\u8c03\u7528\u4f18\u5316\u7684\u8bed\u8a00\u53ef\u4ee5\u4ece CPS \u4e2d\u53d7\u76ca\uff0c\u56e0\u4e3a\u5b83\u5c06\u6240\u6709\u8c03\u7528\u8f6c\u6362\u4e3a\u5c3e\u8c03\u7528\uff0c\u8fd9\u5728\u5185\u5b58\u4f7f\u7528\u65b9\u9762\u53ef\u4ee5\u66f4\u9ad8\u6548\u3002<\/p>\n<\/li>\n<\/ol>\n<h2>\u8fde\u7eed\u4f20\u7403\u98ce\u683c (CPS) \u7684\u7c7b\u578b<\/h2>\n<p>\u4e3b\u8981\u6709\u4e24\u79cd\u7c7b\u578b\u7684\u5ef6\u7eed\uff0c <strong>\u76f4\u63a5\u98ce\u683c<\/strong> \u548c <strong>\u5ef6\u7eed\u4f20\u9012\u98ce\u683c<\/strong>\u3002\u4ee5\u4e0b\u662f\u4e24\u8005\u7684\u6bd4\u8f83\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u98ce\u683c<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u76f4\u63a5\u98ce\u683c<\/td>\n<td>\u76f4\u63a5\u65b9\u5f0f\u4e2d\uff0c\u51fd\u6570\u6267\u884c\u5b8c\u6bd5\u540e\u5c06\u63a7\u5236\u6743\u8fd4\u56de\u7ed9\u8c03\u7528\u51fd\u6570\uff0c\u8fd4\u56de\u503c\u901a\u5e38\u662f\u8ba1\u7b97\u7ed3\u679c\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u6301\u7eed\u4f20\u9012\u98ce\u683c<\/td>\n<td>\u5728 CPS \u4e2d\uff0c\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u989d\u5916\u7684\u53c2\u6570\uff0c\u5373\u5ef6\u7eed\uff0c\u5e76\u5c06\u7ed3\u679c\u4f20\u9012\u7ed9\u6b64\u5ef6\u7eed\u3002\u63a7\u5236\u6d41\u662f\u663e\u5f0f\u7684\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u4f7f\u7528\u3001\u95ee\u9898\u548c\u89e3\u51b3\u65b9\u6848<\/h2>\n<p>CPS \u4e3b\u8981\u7528\u4e8e\u51fd\u6570\u5f0f\u7f16\u7a0b\u8bed\u8a00\u548c\u7ba1\u7406\u5f02\u6b65\u64cd\u4f5c\u3002<\/p>\n<ol>\n<li>\n<p><strong>\u5f02\u6b65 JavaScript<\/strong>\uff1aJavaScript\uff08\u5c24\u5176\u662f Node.js\uff09\u4f7f\u7528 CPS \u6765\u7ba1\u7406\u5f02\u6b65\u975e\u963b\u585e\u64cd\u4f5c\u3002JavaScript \u4e2d\u7684\u56de\u8c03\u5c31\u662f CPS \u7684\u793a\u4f8b\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u51fd\u6570\u5f0f\u7f16\u7a0b<\/strong>\uff1aScheme \u548c Haskell \u7b49\u8bed\u8a00\u4f7f\u7528 CPS \u6765\u5904\u7406\u5faa\u73af\u548c\u5f02\u5e38\u5904\u7406\u7b49\u63a7\u5236\u7ed3\u6784\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u7136\u800c\uff0cCPS \u4e5f\u4f1a\u5bfc\u81f4\u4e00\u4e9b\u95ee\u9898\uff1a<\/p>\n<ul>\n<li><strong>\u53ef\u8bfb\u6027<\/strong>\uff1aCPS \u6709\u65f6\u4f1a\u5bfc\u81f4\u4ee3\u7801\u96be\u4ee5\u9605\u8bfb\u548c\u7406\u89e3\uff0c\u8fd9\u662f\u7531\u4e8e\u56de\u8c03\u5730\u72f1\u9020\u6210\u7684\uff0c\u5c24\u5176\u662f\u5728\u5b58\u5728\u5927\u91cf\u5d4c\u5957\u56de\u8c03\u7684\u60c5\u51b5\u4e0b\u3002<\/li>\n<li><strong>\u6548\u7387<\/strong>\uff1aCPS \u8f6c\u6362\u53ef\u80fd\u4f1a\u56e0\u989d\u5916\u7684\u53c2\u6570\u548c\u51fd\u6570\u8c03\u7528\u800c\u589e\u52a0\u4ee3\u7801\u7684\u5927\u5c0f\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848\u662f\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 <strong>\u627f\u8bfa<\/strong> \u6216\u8005 <strong>\u5f02\u6b65\/\u7b49\u5f85<\/strong> \u5728 JavaScript \u4e2d\u907f\u514d\u56de\u8c03\u5730\u72f1\u5e76\u63d0\u9ad8\u53ef\u8bfb\u6027\u3002<\/li>\n<li>\u4f7f\u7528\u652f\u6301\u5c3e\u8c03\u7528\u4f18\u5316\u7684\u7f16\u7a0b\u8bed\u8a00\u53ef\u4ee5\u51cf\u8f7b\u6548\u7387\u95ee\u9898\u3002<\/li>\n<\/ul>\n<h2>\u6bd4\u8f83<\/h2>\n<p>\u4ee5\u4e0b\u662f CPS \u4e0e\u5176\u4ed6\u7f16\u7a0b\u8303\u5f0f\u7684\u6bd4\u8f83\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7f16\u7a0b\u8303\u5f0f<\/th>\n<th>\u63a7\u5236\u6d41<\/th>\n<th>\u4f7f\u7528\u6848\u4f8b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u8fde\u7eed\u4f20\u9012\u98ce\u683c (CPS)<\/td>\n<td>\u660e\u786e\u4e14\u5177\u6709\u5ef6\u7eed\u6027\u3002<\/td>\n<td>\u975e\u963b\u585e\/\u5f02\u6b65\u64cd\u4f5c\uff0c\u5c3e\u90e8\u8c03\u7528\u4f18\u5316\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u76f4\u63a5\u98ce\u683c<\/td>\n<td>\u9690\u5f0f\uff0c\u51fd\u6570\u8fd4\u56de\u7ed9\u8c03\u7528\u8005\u3002<\/td>\n<td>\u540c\u6b65\/\u963b\u585e\u64cd\u4f5c\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u534f\u7a0b<\/td>\n<td>\u901a\u8fc7\u5141\u8bb8\u51fd\u6570\u6682\u505c\u548c\u6062\u590d\u6267\u884c\u6765\u5b9e\u73b0\u534f\u4f5c\u5f0f\u591a\u4efb\u52a1\u3002<\/td>\n<td>\u590d\u6742\u7684\u63a7\u5236\u6d41\uff0c\u534f\u4f5c\u591a\u4efb\u52a1\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u672a\u6765\u5c55\u671b<\/h2>\n<p>CPS \u5728\u6784\u5efa\u5f02\u6b65\u4ee3\u7801\u65b9\u9762\u7ee7\u7eed\u53d1\u6325\u7740\u91cd\u8981\u4f5c\u7528\uff0c\u5c24\u5176\u662f\u5728 JavaScript \u4e2d\u3002async\/await \u7684\u5f15\u5165\uff08\u5b83\u662f Promises \u7684\u8bed\u6cd5\u7cd6\uff09\u53ef\u4ee5\u770b\u4f5c\u662f\u5bf9\u4f20\u7edf CPS \u7684\u6539\u8fdb\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u597d\u7684\u8bed\u6cd5\u5e76\u907f\u514d\u4e86\u56de\u8c03\u5730\u72f1\u3002<\/p>\n<p>\u968f\u7740 Web \u548c\u670d\u52a1\u5668\u5e94\u7528\u7a0b\u5e8f\u53d8\u5f97\u8d8a\u6765\u8d8a\u590d\u6742\uff0c\u5e76\u53d1\u6027\u53d8\u5f97\u8d8a\u6765\u8d8a\u91cd\u8981\uff0cCPS \u548c\u5176\u4ed6\u5f02\u6b65\u7f16\u7a0b\u8303\u5f0f\u53ef\u80fd\u4f1a\u53d8\u5f97\u66f4\u52a0\u91cd\u8981\u3002\u76ee\u524d\u6b63\u5728\u8fdb\u884c\u6539\u8fdb\u7f16\u7a0b\u8bed\u8a00\u548c\u8fd0\u884c\u65f6\u7cfb\u7edf\u7684\u7814\u7a76\uff0c\u4ee5\u66f4\u597d\u5730\u652f\u6301\u8fd9\u4e9b\u8303\u5f0f\u3002<\/p>\n<h2>\u4ee3\u7406\u670d\u52a1\u5668\u548c CPS<\/h2>\n<p>\u4ee3\u7406\u670d\u52a1\u5668\u5145\u5f53\u5ba2\u6237\u7aef\u5411\u5176\u4ed6\u670d\u52a1\u5668\u5bfb\u6c42\u8d44\u6e90\u7684\u8bf7\u6c42\u7684\u4e2d\u4ecb\u3002\u5904\u7406\u5e76\u53d1\u5ba2\u6237\u7aef\u8bf7\u6c42\u65f6\uff0c\u4ee3\u7406\u670d\u52a1\u5668\u53ef\u80fd\u4f1a\u4f7f\u7528 CPS \u6216\u7c7b\u4f3c\u7684\u5f02\u6b65\u7f16\u7a0b\u8303\u4f8b\u6765\u7ba1\u7406\u8fd9\u4e9b\u8bf7\u6c42\u800c\u4e0d\u4f1a\u9020\u6210\u963b\u585e\uff0c\u4ece\u800c\u63d0\u9ad8\u541e\u5410\u91cf\u548c\u6027\u80fd\u3002<\/p>\n<h2>\u76f8\u5173\u94fe\u63a5<\/h2>\n<ol>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Continuation-passing_style\" target=\"_new\" rel=\"noopener nofollow\">\u7ef4\u57fa\u767e\u79d1\u4e0a\u7684\u5ef6\u7eed\u4f20\u9012\u98ce\u683c<\/a><\/li>\n<li><a href=\"https:\/\/www.cs.utah.edu\/plt\/publications\/icfp07-fyff.pdf\" target=\"_new\" rel=\"noopener nofollow\">\u5ef6\u7eed\u8005\u7684\u827a\u672f<\/a><\/li>\n<li><a href=\"https:\/\/www.microsoft.com\/en-us\/research\/publication\/a-history-of-haskell-being-lazy-with-class\/\" target=\"_new\" rel=\"noopener nofollow\">Haskell \u7684\u5386\u53f2\uff1a\u61d2\u60f0\u4f7f\u7528 Class<\/a><\/li>\n<\/ol>","protected":false},"featured_media":468006,"menu_order":0,"template":"","meta":{"_acf_changed":false,"content-type":"","inline_featured_image":false,"footnotes":""},"class_list":["post-476419","wiki","type-wiki","status-publish","has-post-thumbnail","hentry"],"acf":{"faq_title":"Frequently Asked Questions about <mark>A Deep Dive into Continuation-passing Style (CPS)<\/mark>","faq_items":[{"question":"What is Continuation-passing Style (CPS)?","answer":"<p>Continuation-passing Style (CPS) is a method of managing control flow in computer programming. Instead of returning a value to the caller in the usual way, functions in CPS receive an extra argument (often termed as \"continuation\") representing what should happen after the function finishes its computation.<\/p>"},{"question":"When was Continuation-passing Style (CPS) first mentioned?","answer":"<p>The concept of Continuation-passing Style (CPS) was first introduced by computer scientist Christopher Strachey in the 1960s when exploring denotational semantics, a framework for defining the meanings of programming languages.<\/p>"},{"question":"How does a Continuation-passing Style (CPS) function work?","answer":"<p>In CPS, every function receives an extra argument, representing the continuation of the program. When the function has computed its result, it \"returns\" this result by passing it to the continuation, making control flow explicit.<\/p>"},{"question":"What are the key features of Continuation-passing Style (CPS)?","answer":"<p>The key features of CPS include explicit control flow, increased flexibility, improved handling of non-blocking or asynchronous operations, and enhanced tail call optimization.<\/p>"},{"question":"What types of Continuation-passing Style (CPS) exist?","answer":"<p>There are mainly two types of continuations: direct style and continuation-passing style. In direct style, a function completes its execution and returns control to the calling function. In continuation-passing style, the function passes the result to a received continuation, making the control flow explicit.<\/p>"},{"question":"What are the main uses and problems related to CPS?","answer":"<p>CPS is mostly used in functional programming languages and for managing asynchronous operations. It's useful in JavaScript, particularly in Node.js, and languages like Scheme and Haskell. However, it can lead to problems like reduced code readability (due to callback hell) and increased code size. These can be mitigated by using Promises or async\/await in JavaScript and tail-call optimization in other languages.<\/p>"},{"question":"What is the future perspective of Continuation-passing Style (CPS)?","answer":"<p>CPS continues to be essential in structuring asynchronous code, with developments like async\/await in JavaScript improving upon traditional CPS. As web and server applications become more complex and concurrent, CPS and other asynchronous programming paradigms are likely to become more important.<\/p>"},{"question":"How are proxy servers related to Continuation-passing Style (CPS)?","answer":"<p>Proxy servers, acting as intermediaries for requests from clients seeking resources from other servers, might use CPS or similar asynchronous programming paradigms to manage concurrent client requests without blocking, thereby improving throughput and performance.<\/p>"}]},"_links":{"self":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/wiki\/476419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/wiki"}],"about":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/types\/wiki"}],"version-history":[{"count":0,"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/wiki\/476419\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/media\/468006"}],"wp:attachment":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/media?parent=476419"}],"curies":[{"name":"\u53ef\u6e7f\u6027\u7c89\u5242","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}