Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang print 2 list

I have 2 list:

 List1 = [1,2,3].
 List2 = ["asd", "sda", "dsa"].

How can i print this list in following turn:

1 asd 2 sda 3 dsa

Thank you.

like image 808
0xAX Avatar asked Dec 22 '22 18:12

0xAX


2 Answers

sometimes it's better to reinvent the wheel. in case of erlang - just to understand recursion, tail calls and how to work with lists.

f([], []) -> 
    ok;
f([H1|R1], [H2|R2]) -> 
    io:format("~p ~p", [H1, H2]), 
    f(R1, R2).
like image 107
keymone Avatar answered Dec 25 '22 22:12

keymone


1> lists:zipwith(fun (X1, X2) -> io:format("~p ~p ", [X1,X2]) end, List1, List2).
1 "asd" 2 "sda" 3 "dsa" [ok,ok,ok]
2> 
like image 24
YasirA Avatar answered Dec 25 '22 22:12

YasirA