⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch02s01.html

📁 优秀的java程序开发软件方式与方法,对大家开发程序的时候有指导性帮助
💻 HTML
字号:
<html><head>      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">   <title>1.&nbsp;Continuation&#21021;&#27493;</title><link rel="stylesheet" href="html.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.69.1"><link rel="start" href="index.html" title="Java&#32593;&#32476;&#31243;&#24207;&#21592;&#30475;Continuation"><link rel="up" href="ch02.html" title="Chapter&nbsp;2.&nbsp;Continuation&#65292;call/cc&#20989;&#25968;&#19982;&#22238;&#36864;&#65295;&#21047;&#26032;&#38190;"><link rel="prev" href="ch02.html" title="Chapter&nbsp;2.&nbsp;Continuation&#65292;call/cc&#20989;&#25968;&#19982;&#22238;&#36864;&#65295;&#21047;&#26032;&#38190;"><link rel="next" href="ch02s02.html" title="2.&nbsp;&#36739;&#22797;&#26434;&#30340;continuation&#24212;&#29992;&#65306;coroutine"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">1.&nbsp;Continuation&#21021;&#27493;</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;2.&nbsp;Continuation&#65292;call/cc&#20989;&#25968;&#19982;&#22238;&#36864;&#65295;&#21047;&#26032;&#38190;</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ch02s02.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e142"></a>1.&nbsp;Continuation&#21021;&#27493;</h2></div></div></div><p>Exception&#21040;&#24213;&#26159;&#20160;&#20040;&#65311;&#23427;&#20854;&#23454;&#23601;&#26159;&#19968;&#20010;goto&#65306;&#22914;&#26524;&#21457;&#29983;&#26576;&#26576;&#24773;&#20917;&#23601;&#36339;&#21040;&#26576;&#26576;&#22320;&#26041;&#12290;&#20294;&#26159;&#23427;&#21448;&#19981;&#26159;&#19968;&#20010;&#26222;&#36890;&#30340;goto&#65292;&#22240;&#20026;&#23427;&#20855;&#20307;&#36339;&#21040;&#21738;&#37324;&#25105;&#20204;&#35201;&#21040;&#36816;&#34892;&#26102;&#25165;&#30693;&#36947;&#12290;&#24403;&#28982;&#65292;Exception&#21482;&#33021;&#36339;&#21040;&#24403;&#21069;stack&#19978;&#30340;&#20989;&#25968;&#20013;&#12290;Exception&#30340;&#21478;&#19968;&#20010;&#30475;&#27861;&#26159;&#65292;&#23427;&#22312;try&#30340;&#22320;&#26041;&#21019;&#24314;&#31243;&#24207;&#24403;&#21069;&#30340;&#19968;&#20010;&#8220;&#24555;&#29031;&#8221;&#65292;&#35813;&#24555;&#29031;&#30340;&#19979;&#19968;&#20010;&#25351;&#20196;&#26159;catch&#22788;&#12290;&#24403;&#31243;&#24207;&#25191;&#34892;&#21040;throw&#26102;&#65292;&#30005;&#33041;&#33258;&#21160;&#35843;&#29992;&#35813;&#24555;&#29031;&#65292;&#20063;&#21363;catch&#25104;&#20026;&#19979;&#19968;&#20010;&#25351;&#20196;&#12290;</p><p>&#20107;&#23454;&#19978;&#65292;&#22312;&#27809;&#26377;Exception&#30340;C&#37324;&#65292;&#31243;&#24207;&#21592;&#23454;&#29616;&#31867;&#20284;Exception&#32467;&#26500;&#30340;&#26631;&#20934;&#26041;&#27861;&#23601;&#26159;&#20351;&#29992;setjmp()&#21644;longjmp()&#20004;&#20010;&#20989;&#25968;&#12290;&#31616;&#21333;&#22320;&#35828;&#65292;setjmp()&#23601;&#26159;&#8220;&#20648;&#23384;&#24555;&#29031;&#8221;&#65292;&#32780;longjmp()&#23601;&#26159; &#8220;&#36339;&#33267;&#24555;&#29031;&#8221;&#12290;&#22914;&#26524;&#24744;&#26597;&#19968;&#26597;longjmp()&#30340;&#35828;&#26126;&#65292;&#24744;&#20250;&#21457;&#29616;&#19979;&#38754;&#30340;&#35686;&#21578;&#65306;</p><p>&#8220;<span class="quote">The longjmp() routines may not be called after the routine which called the setjmp() routines returns. &#65288;&#19981;&#33021;&#22312;&#35843;&#29992;setjmp()&#30340;&#20989;&#25968;&#36820;&#22238;&#21518;&#20877;&#35843;&#29992;longjmp()&#20989;&#25968;&#12290;&#65289;</span>&#8221;</p><p>&#25442;&#21477;&#35805;&#35828;&#65292;&#29992;setjmp()/longjmp()&#65288;&#21035;&#30340;Exception&#26426;&#21046;&#20063;&#26159;&#22914;&#27492;&#65289;&#21482;&#33021;&#36339;&#33267;&#20173;&#30041;&#22312;stack&#19978;&#30340;&#24555;&#29031;&#12290;Call/cc&#20989;&#25968;&#19982;Exception&#31867;&#20284;&#65292;&#20294;&#26159;&#23427;&#27809;&#26377;&#36825;&#20010;&#38480;&#21046;&#12290;&#21363;&#20351;&#19968;&#20010;&#20989;&#25968;&#24050;&#32463;&#36820;&#22238;&#65292;&#25105;&#20204;&#36824;&#26159;&#21487;&#20197;&#36339;&#21040;&#20989;&#25968;&#36816;&#34892;&#26102;&#23384;&#20648;&#19979;&#30340;&#24555;&#29031;&#65292;&#36825;&#26679;&#35813;&#20989;&#25968;&#36816;&#34892;&#23436;&#26102;&#20250;&#20877;&#27425;&#36820;&#22238;&#12290;</p><p>&#19979;&#38754;&#25105;&#20204;&#26469;&#30475;&#19968;&#20010;&#31616;&#21333;&#30340;Ruby&#20363;&#23376;&#12290;&#25105;&#20204;&#30475;&#30475;call/cc&#30340;&#20855;&#20307;&#29992;&#27861;&#21644;&#22914;&#20309;&#29992;call/cc&#27169;&#25311;Exception&#12290;&#35760;&#20303;&#65292;C/C++/Java&#19968;&#31867;&#30340;&#35821;&#35328;&#20013;&#27809;&#26377;&#30456;&#24212;&#30340;&#20989;&#25968;&#12290;</p><pre class="programlisting">def grand_child(cont) cont.call("GRANT CHILD")enddef child(cont)  grand_child(cont)  return "CHILD"enddef parent  return callcc { |cc|    child(cc)  }endanswer = parent()puts answer</pre><p>&#36816;&#34892;&#35813;&#31243;&#24207;&#65292;&#25105;&#20204;&#24471;&#21040;&#36755;&#20986;GRAND CHILD&#12290;</p><p>&#25105;&#20204;&#26469;&#20180;&#32454;&#30475;&#30475;&#36825;&#20010;&#20363;&#23376;&#12290;&#25105;&#20204;&#30475;&#21040;&#65292;callcc&#20989;&#25968;&#65288;Ruby&#37324;&#30340;call/cc&#65289;&#25509;&#21463;&#19968;&#20010;closure&#20316;&#20026;&#21442;&#25968;&#12290;Closure&#26159;&#24456;&#22810;functional&#35821;&#35328;&#21644;&#21160;&#24577;&#35821;&#35328;&#30340;&#26680;&#24515;&#27010;&#24565;&#65292;&#21487;&#24796;&#30340;&#26159;&#65292;C/C++/Java&#31561;&#35821;&#35328;&#20013;&#20063;&#27809;&#26377;&#19982;&#20043;&#30452;&#25509;&#23545;&#24212;&#30340;&#27010;&#24565;&#12290;&#22823;&#33268;&#22320;&#35828;&#65292;closure&#23601;&#26159;&#19968;&#20010;&#21311;&#21517;&#20989;&#25968;&#12290;&#19978;&#38754;callcc&#21518;&#38754;&#30340;closure&#22823;&#33268;&#30456;&#24403;&#20110;&#65306;</p><pre class="programlisting">def anonymous_function(cc)  child(cc)end</pre><p>Callcc&#20989;&#25968;&#20250;&#39532;&#19978;&#35843;&#29992;&#36825;&#20010;closure&#12290;&#37027;&#20040;callcc&#20256;&#32473;&#36825;&#20010;closure&#30340;&#21442;&#25968;cc&#26159;&#20160;&#20040;&#21602;&#65311;&#31572;&#26696;&#26159;current continuation&#65288;&#24403;&#21069;continuation&#65289;&#12290;&#24744;&#30340;&#19979;&#19968;&#20010;&#38382;&#39064;&#19968;&#23450;&#26159;&#65292;&#20160;&#20040;&#26159;current continuation&#65311;</p><p>&#31616;&#21333;&#22320;&#35828;&#65292;current continuation&#23601;&#26159;&#24403;&#21069;&#31243;&#24207;&#30340;&#19968;&#20010;&#24555;&#29031;&#12290;&#22914;&#26524;&#24744;&#35760;&#24471;&#25105;&#20204;&#20043;&#21069;&#35762;&#36807;&#30340;&#65292;continuation passing style&#20013;&#21097;&#19979;&#30340;&#25805;&#20316;&#20250;&#20316;&#20026;&#19968;&#20010;&#21442;&#25968;&#65288;continuation&#65289;&#20256;&#32473;&#23376;&#20989;&#25968;&#12290;&#39038;&#21517;&#24605;&#20041;&#65292;current continuation&#30340;&#23450;&#20041;&#23601;&#26159;&#31243;&#24207;&#25191;&#34892;&#21040;&#29616;&#22312;&#36824;&#21097;&#19979;&#30340;&#25805;&#20316;&#65288;&#36825;&#22312;&#36923;&#36753;&#19978;&#31561;&#20215;&#19982;&#31243;&#24207;&#24403;&#21069;&#30340;&#19968;&#20010;&#24555;&#29031;&#65289;&#12290;&#22914;&#26524;&#25105;&#20204;&#30475;&#30475;&#36825;&#20010;&#31243;&#24207;&#65292;&#37027;&#20040;&#24456;&#26126;&#26174;&#31243;&#24207;&#25191;&#34892;&#21040;callcc&#26102;&#21097;&#19979;&#30340;&#25805;&#20316;&#26159;&#65306;return callcc&#30340;&#32467;&#26524;&#65292;&#23558;&#35813;&#20540;&#36171;&#20104;answer&#65292;&#36755;&#20986;answer&#65292;&#28982;&#21518;&#36864;&#20986;&#12290;&#25152;&#20197;&#25105;&#20204;&#30340;closure&#25509;&#21040;&#30340;&#21442;&#25968;cc&#23601;&#26159;&#36827;&#34892;&#36825;&#20123;&#25805;&#20316;&#30340;&#19968;&#20010;&#8220;&#20989;&#25968;&#8221;&#65292;&#25110;&#32773;&#35828;continuation&#12290;</p><p>&#25509;&#19979;&#26469;&#25105;&#20204;&#30475;&#21040;&#65292;closure&#25226;&#36825;&#20010;continuation&#20256;&#32473;child&#65292;child&#21448;&#25226;&#23427;&#20256;&#32473;grand_child&#12290;&#36825;&#26102;&#65292;grand_child&#35843;&#29992;&#65306;</p><pre class="programlisting">cont.call(&#8220;GRAND CHILD&#8221;)</pre><p>&#36825;&#27573;&#20195;&#30721;&#30340;&#24847;&#24605;&#26159;&#65292;&#25191;&#34892;cont&#20445;&#23384;&#30340;continuation&#65292;&#24182;&#23558;&#23383;&#20018;GRAND CHILD&#20316;&#20026;callcc&#30340;&#36820;&#22238;&#20540;&#12290;&#25442;&#21477;&#35805;&#35828;&#65292;&#36339;&#21040;continuation&#20445;&#23384;&#30340;&#24555;&#29031;&#22788;&#32487;&#32493;&#25191;&#34892;&#12290;&#22914;&#26524;&#25105;&#20204;&#30475;&#30475;&#35813;continuation&#25152;&#21253;&#21547;&#30340;&#25805;&#20316;&#65292;&#25105;&#20204;&#23601;&#21487;&#20197;&#30693;&#36947;&#25509;&#19979;&#26469;&#20250;&#21457;&#29983;&#20160;&#20040;&#65306;&#36820;&#22238;&#23383;&#20018;GRAND CHILD&#65292;&#36171;&#20540;&#32473;answer&#65292;&#36755;&#20986;answer&#65288;&#25105;&#20204;&#20250;&#30475;&#21040;GRAND CHILD&#65289;&#65292;&#28982;&#21518;&#36864;&#20986;&#12290;</p><p>&#29616;&#22312;&#25105;&#20204;&#37325;&#26032;&#30475;&#30475;&#36825;&#27573;&#20195;&#30721;&#65292;&#24744;&#33021;&#30475;&#20986;&#23427;&#20107;&#23454;&#19978;&#23601;&#23454;&#29616;&#20102;&#19968;&#20010;Exception&#26426;&#21046;&#21527;&#65311;&#27880;&#24847;&#21040;continuation&#21487;&#20197;&#20687;&#21035;&#30340;&#20540;&#19968;&#26679;&#20316;&#20026;&#21442;&#25968;&#25110;&#32773;&#20445;&#23384;&#22312;&#20840;&#23616;&#21464;&#37327;&#20013;&#65292;&#25152;&#20197;&#23613;&#31649;&#36825;&#37324;continuation&#30475;&#36215;&#26469;&#20687;Exception&#65292;&#20294;&#26159;&#25105;&#20204;&#21487;&#20197;&#29992;&#23427;&#36339;&#33267;&#20960;&#20046;&#20219;&#20309;&#22320;&#26041;&#65292;&#32780;&#19981;&#20250;&#26377;&#31867;&#20284;Exception&#30340;&#38480;&#21046;&#12290;</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="ch02.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ch02s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&nbsp;2.&nbsp;Continuation&#65292;call/cc&#20989;&#25968;&#19982;&#22238;&#36864;&#65295;&#21047;&#26032;&#38190;&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;2.&nbsp;&#36739;&#22797;&#26434;&#30340;continuation&#24212;&#29992;&#65306;coroutine</td></tr></table></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -