Erlang print 2 list

I have 2 lists:

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

How can I print this list in the following order:

1 asd 2 sda 3 dsa

Thanks.

+4
source share
2 answers
 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> 
+5
source

sometimes it's better to reinvent the wheel. in the case of erlang, just for understanding 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). 
+6
source

Source: https://habr.com/ru/post/1337020/


All Articles