how do i repeat a func in a loop, while returning the func just before each iteration

MEENA SELVAM meena_selvam@REDACTED
Fri Aug 5 02:22:58 CEST 2005


In the below code, the return value of the entire
function is some detail about sessions. Infact as part
of this function call, the other function foo is
called with different parameters each time.. some type
of recursion is built in the function definition of
nselect_cols. But leaving those details aside,

I would like to know how I can repeat the function
nselect_cols say 10 times, each time the PId parameter
being changed to 1,2, 3,... upto 10. But I should be
able to get the return value as before.(return value
of snasSessionDetailTable is what function foo
returns)


snasSessionDetailTable(get_next, RowIndex, Cols) ->
        
    {atomic, Res} =
        reg:transaction(
          fun() ->
               case .... of
                   {Op, [...] = Oid} ->

                          ....
                          ... 
                      nselect_cols(NCols, Oid,
                                               
            fun foo/2, {XId, SId, PId},               
                    
            ?....,
              ?...),

                  end_of_table ->
                          end_of_table(Cols)
                  end
          end),
    Res.

When I try to write a seperate function as follows: 

do_for_all_ports(PId,NCols, Oid, XId, SId)  
                     when PId < 10 ->
                    Res = nselect_cols(NCols, Oid,
             fun foo/2, {XId, SId, PId},
                                       ?..., ?...),
        do_for_all_ports(PId+1,NCols, Oid, XId, SId). 
                                     
and call this instead, then the new code becomes:

snasSessionDetailTable(get_next, RowIndex, Cols) ->
        
    {atomic, Res} =
        reg:transaction(
          fun() ->
               case .... of
                   {Op, [...] = Oid} ->

                          ....
                      do_for_all_ports(1,NCols, Oid,
XId, SId) 
                          
                  end_of_table ->
                          end_of_table(Cols)
                  end
          end),
    Res.

                     
But the problem with this is, the function
nselect_cols
results in calling multiple calls to foo as before,
when PId is 1; but before in the original code the
output of these multiple calls to foo was the return
value of the outer level SnasSessionDetailTable
function.(expected behaviour). The moment I add the
looping behaviour with the Pid parameter being
incremented each time, the output of the calls to foo
are no longer return values of the outer level
SnasSessionDetailTable function. the return value
becomes those corresponding to PId 10 only.

How do i make it to return every time?

PS: Just to add more info, the function foo has the
format foo(colno,{XId, SId, PId})   and colno is
nothing but NCols which is changed from 1 to some "n"
due to recursion built within nselect_cols definition.

meena

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the erlang-questions mailing list