[erlang-questions] A function as an element of a list of action

Erik Søe Sørensen eriksoe@REDACTED
Mon Jan 28 11:09:28 CET 2013


I think (though I'm not sure) I understand what you're trying to do.
If I'm completely off track, perhaps you could be more concrete in your
example - especially wrt. what the output should be?

If I understand correctly,
- having Lc be a dict is a bad idea - if you want to preserve the order of
the commands. Use a list instead:

Lc = lists:map(fun({density,{true,Value}}, Dict) -> ... end, Lf)

- You don't use Value. Where should it be used? I presume it should somehow
be part of the context of the inner funs.

I think what you want could be something like:
Lc = % List of command functions
    lists:map(fun({density,{true,Value}}, Dict) ->
                  [fun(Dict) ->
                  Dict0=dict:store(top, calc_top(Value), Dict);
                  Dict1=dict:store(bottom, calc_bottom(Value), Dict0);
                  dict:store(side, calc_side(Value, Dict1)
                  end];
                  ...
              end,
              Lf),
...
lists:foldl(fun(F,P) -> F(P) end, Params0, Lc)

(Not tested!)
Hoping this helps (which depends heavily of how well I understood your
problem),
/Erik

2013/1/25 Micheus <micheus@REDACTED>

> Hi there,
>
> I did a google search but I couldn't find anything appropriated or I
> didn't know how to ask about that.
>
> I would like to generate a list (based in some criterias - so, it can be
> variable) in which each element is an function to be called posteriorly.
> Something like a "script".
> These functions will receive the same parameters.
>
> I have an list of "fields" that tell me what I need to do (function to
> call) . What I'm looking for is something like this:
>
> +----------------------------------------------------------------------------------------+
>  :
> Lf=[{density,{true,Value}}, {ws,{trueValue}}, {hs,{trueValue}}, ...
> ,{he,{trueValue}}],
>  :
> Lc=lists:foldl(
>     fun({density,{true,Value}}, Dict) ->
>           Dict0=dict:store(top, calc_top/1, Dict);
>           Dict1=dict:store(bottom, calc_bottom/1, Dict0);
>           dict:store(side, calc_side/1, Dict1);
>        ({bf,{true,Value}}, Acc) ->
>           Dict0=dict:store(bottom, calc_bottom/1, Dict);
>           dict:store(side, calc_side/1, Dict1);
>        ({sf,{true,Value}}, Acc) ->
>           dict:store(side, calc_side/1, Dict);
>          :
>        (_, Dict) -> Dict
> dict:new(), Lf),
>
> dict:fold(_Key, Func, Params0) ->
>        Func(Params0)
> Params, Lc),
>  :
>
> +----------------------------------------------------------------------------------------+
>
> Does someone can help me?
>
> TIA
> Micheus
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130128/f67df6e4/attachment.htm>


More information about the erlang-questions mailing list