I'm trying to use maplist to filter a list of elements by limiting the length of each of the element, and here is what I tried
maplist(atom_length(2,X),[aa,bb,cc,asd],Result).
ERROR: apply:maplist_/3: Undefined procedure: atom_length/4
ERROR: However, there are definitions for:
ERROR: atom_length/2
I expect to get
Result = [aa,bb,cc]
A little help is required. Thanks.
A predicate that provides the functionality you require is findall_member/4
. You can find a description and an implementation of this predicate in the Richard O'Keefe Prolog library proposal. For example:
| ?- findall_member(Atom, [aa,bb,cc,asd], atom_length(Atom,2), Result).
Result = [aa, bb, cc]
yes
The third argument of the findall_member/4
predicate is a test that is applied to each member of the list to filter the results.