Re: CPS Conventions?
"David McClain (as dbm at refined-audiometrics dot com)" <[email protected]> Thu, 30 Jul 2026 15:35:58 -0700
| Newsgroups | gmane.lisp.lispworks.general |
|---|---|
| Message-ID | <[email protected]> |
Er, sorry, just to let you know - I’m asking on this list because i already researched the web for this same question, and all I get are into to CPS and Andrew Appel’s "Compiling with Continuations". Those are great, but they don’t answer the question of how to deal with shared dynamic state… > On Jul 30, 2026, at 15:28, David McClain <[email protected]> wrote: > > I”m working deeply on a system in Lisp that has a lot in common with CPS code (Continuation Passing Style). > > The point most alike is that the code never “returns” to a “caller”. Messages are sent to computable functional closures, and embedded in some messages is the address of the next computable closure to send any results to. > > With such a system I can completely ignore threads and locks and get all of my CPU Cores humming to 100%. But I do have to write my code in purely functional style (thread safe - enables automatic parallel concurrency) > > The difference between CPS and my message passing code, is that on a Call/Return architecture, CPS can be simulated by way of a trampoline, which tosses away any return addresses stacked up on the system return stack. Those return addresses are no needed in CPS code. > > My message system also does not have return addresses stacking up. But I did run into an analogous situation when I tried to give my messages a sense of shared dynamic state - like a Cancel flag that requests code to voluntarily cancel their computing, presumably because a result has already been obtained from other means. > > Each time I set up a ONCE Gate - a lambda closure that forwards a result to another closure, and then becomes inert, so that only one message will pass. Each time I set one of these up, I also pair it with a Cancel Flag prepended onto the shared dynamic state (a PList). > So when a message arrives, just before forwarding and becoming inert, I also set the cancel flag to allow any other closures which might be working toward the same goal, to be informed that an answer has already arrived and their continued work is unnecessary. > > So each time I set up a ONCE gate along the computational path of some Logical Task I end up prepending a PList of shared state with another Cancel Flag. This leads to an indefinite extension of the PList - akin to the buildup of useless return addresses in CPS. > > So my main interest in this thread is to hear from others, what best practices have you seen for shared dynamic state in CPS code? CPS Code would run into the exact same trouble as my system, for shared dynamic state. > > - DM > > _______________________________________________ Lisp Hug - the mailing list for LispWorks users [email protected] http://www.lispworks.com/support/lisp-hug.html