[erlang-questions] callcc or CPS in Erlang?

Dmitrii Dimandt dmitrii@REDACTED
Wed Jul 27 12:39:17 CEST 2011

Something along the lines of

next(_, []) ->

next(Fun, [H|T]) ->
      F = fun()
      Result = Fun(H),

      {Result, F}.

test() ->
        Params = [[1], [1, 2], [1, 2, 3]],
        Start = next(fun erlang:length/1, Params),

output(ok) ->

output({Result, F}) ->
      io:format("~w", [Result]),

      NewResult = F(),


> In a normal scenario, I would prefer serial code, admittedly.
> However, the scenario that I want to implement is the following: I want to retry the same piece of code several times, each time with a different settings.  The ways to do so are either making sure that each step in the code is a function (i.e., CPS), or exploiting callcc.
> Other ideas?
> G.
> On Wed, Jul 27, 2011 at 7:23 AM, Jon Watte <jwatte@REDACTED> wrote:
> One of the biggest problems of CPS code in Twisted or Node or most other frameworks using that mechanism, is that it ends up with single-threaded servers, making poor use of multi-threaded hardware.
> In Erlang, a process is comparable to the cost as a continuation with a function lambda in other languages (give or take a little bit, depending on specifics of implementation and use).
> Write your code serially, in a process, and talk to it using messaging. It's easier to write, debug, and understand that way. Because of data being immutable, there is no risk of threading data hazards.
> Sincerely,
> jw
> --
> Americans might object: there is no way we would sacrifice our living standards for the benefit of people in the rest of the world. Nevertheless, whether we get there willingly or not, we shall soon have lower consumption rates, because our present rates are unsustainable. 
> On Tue, Jul 26, 2011 at 12:39 AM, Guy Wiener <wiener.guy@REDACTED> wrote:
> Hello everyone,
> Is there some equivalent to callcc (as in Scheme or Ruby) in Erlang?
> Alt., is there some what to encourage Continuation-Passing Style programming in Erlang, other than just recommending that all consequent function calls will be in tail-call position?
> Thanks,
>   Guy
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

Dmitrii Dimandt

Erlang in Russian


LinkedIn: http://www.linkedin.com/in/dmitriid
GitHub: https://github.com/dmitriid

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110727/c3276075/attachment.htm>

More information about the erlang-questions mailing list