Display function in Erlang

In addition to having a map function with multiple arities (up to 4), Prolog allows you (under certain circumstances) to match the multiple arity function into a single list. Suppose you want to check if "x" is a member of several lists. You can do:

maplist(member(x),[[a,b,c,x],[3,f,s,x]]). 

The first member argument is included, and all this is displayed in a list.

Question 1: Something similar to Erlang? I cannot find it in the documentation, but then again I can not find it in any Prolog documentation.

Question 2: How to use a card (and similar functions) with multiple states? Roll up your own?

Thanks.

+6
list lambda erlang functional-programming prolog
source share
2 answers

Maybe something like:

 23> lists:map(fun(L) -> lists:member(42,L) end, [[1,5,8,4],[13,42],[7,2,10]]). [false,true,false] 24> 
+3
source share

There are lists:map/2 , as well as lists:

 1> lists:map(fun(L) -> lists:member(42,L) end, [[1,5,8,4],[13,42],[7,2,10]]). [false,true,false] 2> [ lists:member(42,L) || L <- [[1,5,8,4],[13,42],[7,2,10]] ]. [false,true,false] 
+3
source share

All Articles