[erlang-questions] callcc or CPS in Erlang?
Thu Jul 28 04:09:58 CEST 2011
It sounds like what you want is just a way to create a closure, not "CPS"
per se. Continuation Passing Style is a specific approach to slice workloads
into separate function invocations; one use of which is to implement a poor
man's threading system.
You could use a fun that returns a function to execute with the values bound
(a closure), or parameterized modules.
make_function(Arg1, Arg2) ->
Whatever * Arg1 + Arg2
A = make_function(1, 2),
B = make_function(3, 4),
3 = A(1),
4 = A(2),
7 = B(1).
10 = B(2).
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 Wed, Jul 27, 2011 at 3:05 AM, Guy Wiener <wiener.guy@REDACTED> wrote:
> 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?
> 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.
>> 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?
>>> erlang-questions mailing list
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions