On 17 June 2011 14:00, Alessio Stalla <alessiosta...@gmail.com> wrote:
> On Jun 14, 7:40 pm, Fabrizio Giudici <fabrizio.giud...@tidalwave.it> > wrote: > > On 06/14/2011 02:11 PM, Kevin Wright wrote: > > > > > The current approach taken by Scala/C# is therefore reification of > > > *delimited* continuations to stop you blowing the stack. This isn't > > > exactly an easy thing to get right, hence the fact that it's a fairly > > > recent arrival (the growing popularity of asynchronous designs, and > > > the usefulness of continuations for these have also helped spur > adoption) > > > > Is this the part related to CPS and tail recursion, right? Not related > > to my post, but since I'm here, perhaps I can start understanding > > something around. > > > > So, if in my post I refer to my example as a very simple CPS, I sholdn't > > be bashed. By Kevin at least :-) > > Hi Fabrizio :) I'm no expert in functional programming, but > nevertheless I have some understanding of continuations. > Code written in CPS has only function calls without return statements: > "returning" a value means calling a function (called a continuation). > So, in a naive implementation, the progress of the computation > eventually blows the stack. Tail call optimization or TCO (a > generalization of tail recursion) is a way to perform certain function > calls without consuming stack space, translating them into jumps. > Since luckily in code written in CPS all calls to continuations are > "in tail position" and thus eligible for TCO, that is a way to > implement CPS without using too much stack space. > Note however, to add some confusion ;), that user code is rarely > written in CPS in general; transformation to CPS is a technique used > in certain compilers, not necessarily to implement continuations (that > can be implemented with other techniques as well). > > To return to your original example, I have not clear the effect of > calling doRetrieve() since it doesn't return anything and it doesn't > take any argument. Does it make the service invoke notifyDatum()? In > that case, yes, I'd say it's a form of CPS :) although I believe CPS > can hardly be called a pattern since it doesn't solve a specific > problem, it's too generic, in my opinion. > > Agreed :) Phrases like "callback style" or even just "asynchronous" would probably be more useful in this context, as they better reflect the intent of the code. -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to javaposse@googlegroups.com. To unsubscribe from this group, send email to javaposse+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.