Erlang/OTP Forums

Author Message

<  Erlang  ~  foldl function call itself

mccmike
Posted: Fri Mar 05, 2010 12:32 am Reply with quote
Joined: 16 Feb 2010 Posts: 3
Stepping thru a large deep list

Within this list are tuples that contain lists.

Is it possible to call the foldl fun from within the foldl fun when I encounter one of these tuples?

Trying to do this

Walk = fun(Rec, Acc) ->
io:format("~nWalking ~p",[Rec])

case is_tuple(Rec) of
true -> lists:foldl(Walk, [], (Rec tuple list)
false -> ok
end
end,

lists:foldl(Walk, [], Doc).
View user's profile Send private message
bpuzon
Posted: Fri Mar 05, 2010 12:55 pm Reply with quote
User Joined: 05 Aug 2009 Posts: 23 Location: Cracow, Poland
You have to pass the function as the paramenter - like:

Code:

   Walk = fun(Rec, {Fun, Acc}) ->
         io:format("~nWalking ~p~n",[Rec]),
         case is_tuple(Rec) of
             true ->  {Fun, lists:foldl(Fun, {Fun, Acc}, (Rec tuple list))};
             false -> {Fun, ok}
         end
      end,
    lists:foldl(Walk, {Walk, []}, Doc)

_________________
Saludos,
Bartłomiej Puzoń
Erlang Solutions
View user's profile Send private message Visit poster's website
mccmike
Posted: Fri Mar 05, 2010 4:02 pm Reply with quote
Joined: 16 Feb 2010 Posts: 3
Thanks
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum