<div dir="ltr"><div class="gmail_quote">On Sat, Sep 27, 2008 at 2:56 AM, Joel J. Adamson <<a href="mailto:adamsonj@email.unc.edu">adamsonj@email.unc.edu</a>> <span dir="ltr"><<a href="mailto:adamsonj@email.unc.edu">adamsonj@email.unc.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">>>>>> "DR" == David Rush <<a href="mailto:kumoyuki@gmail.com">kumoyuki@gmail.com</a>> writes:<br>

<br>
    DR> Don't get me wrong - I am a big fan of call/cc. But it is a<br>
    DR> *big* gun and it is silly to use it for relatively simple things<br>
    DR> when a trivial code rearrangement will also produce code that is<br>
    DR> more sound, easier to reason about, and potentially faster.<br>
<br>
So can you give a non-trivial example?</blockquote><div><br></div><div>Well I already did earlier in this thread. For a larger example, I'd have to point you to a rather larger program than would fit in the margin of this email :)</div>
<div><br></div><div>Some years ago I did quite a bit of (very unscientific) benchmarking w/rt different Scheme implementations and discovered the important of type-coherence to the performance of compiled code. The poster child for this is, of course, Stalin, but *every* Scheme compiler has a 'unsafe' mode (which disables type-checking to some degree), and using explicit CPS makes it easier to keep your code correct under those conditions.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">  As I said, I used it because my<br>
problem was the sort of thing that intro textbooks (e.g., The Scheme<br>
Programming Language) say to use it for.</blockquote><div><br></div><div>Well, that's because it's an easy way to demonstrate the power of the construct. It is however poor software engineering as the use of call/cc frequently gets you involved in the law of unintended consequences. One correspondent actually pointed out to me that call/cc is closely akin to set! as a side-effecting operation. It certainly can have global consequences as it is a run-time implementation of a global compile-time transformation.</div>
<div><br></div><div>Which is all different from what I am suggesting. call/cc is - just like macros - something where most of the time there is a cleaner and more elegant way to achieve the same effect. Those few times where you do need it, there is literally no other other way.</div>
<div><br></div><div>For example, one place where I did use call/cc heavily was in transforming a yacc (well a scheme equivalent) generated parser from using a model where it controlled all the IO into one where it was event-driven. I needed a large-scale, global transformation of code I did not control and call/cc fit the bill perfectly. I also paid for it heavily with a program that ran rather slower and allocated way more heavily than it needed too - as I discovered when I rewrote the parser from scratch as an event-driven system.</div>
<div><br></div><div>My point is simply this - any tail-call is a continuation invocation. The fact that we can pass anonymous functions around with ease in Scheme means that we can create whatever continuation we need to be executed and pass it directly to the tail-call where it should be invoked. And the really great thing is that we need *not* invoke full call/cc when we do this. We get all this for free because of the requirement for full tail-call optimization. You just need to remain aware of when you are making tail-calls - and you should be doing that anyway.</div>
<div><br></div><div>david</div></div>-- <br>GPG Public key at <a href="http://cyber-rush.org/drr/gpg-public-key.txt">http://cyber-rush.org/drr/gpg-public-key.txt</a><br>
</div>