<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Feb 10, 2014, at 4:52 PM, Matthew Johnson wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="font-family: 'Lucida Grande'; font-size: medium; "><span style="font-family: arial, sans-serif; font-size: 13px; ">Why does (lambda (x) (e x)) make it evaluate once and stop? I mean how<span class="Apple-converted-space"> </span></span><span style="font-family: arial, sans-serif; font-size: 13px; ">come when the evaluator gets to the call it doesn't get stuck in a loop?</span><span style="font-family: arial, sans-serif; font-size: 13px; "> </span></div></span></blockquote><div><br></div><div><br></div><div>This explicit function gets "copied" over and over again during function calls (beta-value reductions) during an evaluation. When it is called the 'e' inside contains (references to) the original function so there is no danger that the infinite loop unfolds -- because it is waiting for the next explicit call. </div><div><br></div><div>;; --- </div><br><blockquote type="cite"><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; ">but i really don't see why one would ever bother to do so. What are the benefits? the cost (hard to read / write / understand) seems high. </span></blockquote></div><br><div><br></div><div>CPS is a programming technique that occasionally comes up in program designs: </div><div> -- if you must implement a recursive algorithm in a language w/o recursion, cps has eliminated it -- systematically </div><div><span class="Apple-tab-span" style="white-space:pre"> </span>[this situation used to be common when I started teaching; now it's rare]</div><div> -- if you need to suspend a computation temporarily, the 'k' is what you don't call but stick into a known place from where to resume</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>[web programs often have to obey this discipline: suspend k, hand control to user to fill out some form, resume k]</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>cps provides this capability -- systematically </div><div> -- if you need to write sophisticated interleaving of routines in a language that doesn't provide it, cps supports it -- systematically </div><div><br></div><div>The 'systematically' says that a programmer can blindly use the transformation and then modify it at some places to get things right. </div><div><br></div><div>;; --- </div><div><br></div><div>The transformation is also used inside of compilers as Yuhao mentions. </div></body></html>