<p>Hi Ladislav,</p>
<p>I can't understand what you mean with your functions. Could you please give more explanation? Thanks.</p>
<p>Best regards,<br>
Barco</p>
<div class="gmail_quote">On Nov 18, 2011 6:02 PM, "Ladislav Lenart" <<a href="mailto:lenartlad@volny.cz">lenartlad@volny.cz</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello.<br>
<br>
I add only one or two notes/ideas...<br>
<br>
I think the Fun application should look like:<br>
<br>
    Value = Fun(lists:reverse(<u></u>HeadElements)).<br>
<br>
to preserve the order of the Fun arguments.<br>
<br>
You can also change it to:<br>
<br>
    apply(Fun, lists:reverse(HeadElements)).<br>
<br>
You will then be able to use it like this:<br>
<br>
    some_fun(A, B, C) -> ...<br>
<br>
    some_mod:mapn(fun some_fun/3, [L1, L2, L3]).<br>
<br>
instead of the current form:<br>
<br>
    some_fun([A, B, C]) -> ...<br>
<br>
    some_mod:mapn(fun some_fun/1, [L1, L2, L3])<br>
<br>
But this is just a cosmetic issue which comes with<br>
a performance penalty.<br>
<br>
<br>
HTH,<br>
<br>
Ladislav Lenart<br>
<br>
<br>
On 18.11.2011 07:45, Ryan Huffman wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If you wanted to be able to do n-lists I don't think there is a<br>
"pretty" way to do it.  You could modify Dmitry's suggestion:<br>
<br>
mapn(Fun, Lists) -><br>
     mapn(Fun, Lists, []).<br>
<br>
mapn(_Fun, [[] | _], MappedList) -><br>
     lists:reverse(MappedList);<br>
mapn(Fun, Lists, MappedList) -><br>
     {HeadElements, RestLists} = lists:foldl(<br>
         fun([H | Rest], {HeadElements, RestLists}) -><br>
                 {[H | HeadElements], [Rest | RestLists]}<br>
         end, {[], []}, Lists),<br>
     Value = Fun(HeadElements),<br>
     mapn(Fun, lists:reverse(RestLists), [Value | MappedList]).<br>
<br>
and call it like so:<br>
<br>
mapn(fun(L) ->  lists:sum(L) end, [[1,2,3],[4,5,6],[7,8,9]]).<br>
<br>
Ryan<br>
<br>
On Thu, Nov 17, 2011 at 10:38 PM, Barco You<<a href="mailto:barcojie@gmail.com" target="_blank">barcojie@gmail.com</a>>  wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Dmitry,<br>
What your suggested can really solve my problem, but it's not<br>
Tail-Recursion. The tail-recursed solution should look like this;<br>
map2(_Fun, [], []) -><br>
    [];<br>
map2(Fun, L1, L2) -><br>
    map2(Fun, L1, L2, []).<br>
map2(_Fun, [], [], L) -><br>
    lists:reverse(L);<br>
map2(Fun, [H1 | T1], [H2 | T2], L) -><br>
    map2(Fun, T1, T2, [Fun(H1, H2) | L]).<br>
<br>
However, I'm still disappointed with the list comprehension which is<br>
different from what I intuitively imagine about it.<br>
<br>
Regards,<br>
Barco<br>
On Fri, Nov 18, 2011 at 1:49 PM, Dmitry Demeshchuk<<a href="mailto:demeshchuk@gmail.com" target="_blank">demeshchuk@gmail.<u></u>com</a>><br>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
My guess is you have to zip them together, or just write a<br>
tail-recursed function:<br>
<br>
map2(Fun, [H1 | T1], [H2 | T2]) -><br>
    [Fun(H1, H2) | map2(Fun, T1, T2)];<br>
map2(Fun, [], []) -><br>
    [].<br>
<br>
The second option definitely isn't a list comprehension, but it<br>
requires less memory and has lesser complexity.<br>
<br>
On Fri, Nov 18, 2011 at 9:45 AM, Barco You<<a href="mailto:barcojie@gmail.com" target="_blank">barcojie@gmail.com</a>>  wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dear Erlangers,<br>
<br>
I hope to get a list from two lists like this:<br>
[{a1,b1}, {a2,b2}, {a3,b3}]<-     [a1, a2 a3],  [b1, b2, b3].<br>
But if I use list comprehension, I got:<br>
10>    [{D1,D2} ||  D1<- [a1,a2,a3], D2<- [b1,b2,b3]].<br>
[{a1,b1},<br>
  {a1,b2},<br>
  {a1,b3},<br>
  {a2,b1},<br>
  {a2,b2},<br>
  {a2,b3},<br>
  {a3,b1},<br>
  {a3,b2},<br>
  {a3,b3}]<br>
<br>
So, my questions is how to comprehend list in synchronous way in order<br>
to<br>
get what I want, rather than to compose the elements from two lists in<br>
all<br>
possible situations.<br>
<br>
Thank you,<br>
Barco<br>
______________________________<u></u>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a><br>
<br>
<br>
</blockquote>
<br>
<br>
<br>
--<br>
Best regards,<br>
Dmitry Demeshchuk<br>
</blockquote>
<br>
<br>
______________________________<u></u>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a><br>
<br>
<br>
</blockquote>
______________________________<u></u>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a><br>
<br>
<br>
</blockquote>
<br>
<br>
</blockquote></div>