Ans Piter
Ans Piter

Reputation: 573

Filtering random-outcomes from maplist/3 result

I wish filter out this list List=['F1',a1,a2,' LF2',a1,a2] with predicate is_upper/2 and maplist/3 below

is_upper(Elem,Res) : if Elem is uppercase atom, it will be assigned to Res then i'd like to put all uppercase atom into list List_Upper

i try this ;

?- maplist(is_upper,List,List_upper).
List_Upper = ['F1',_A,_B,'F2',_C,_D,'F3',_E,_F] ? ;

how I can filter the outs-random _A,_B...

expcted Result :

 List_Upper = ['F1','F2','F3'] 

regards

Upvotes: 1

Views: 64

Answers (1)

Ans Piter
Ans Piter

Reputation: 573

include/3 to collects elements of true resulte and exclude/3 for the falses

| ?- include(is_lower,['FUNCTOR1','arg1','arg2','FUNCTOR2','arg3','arg4','FUNCTOR3','arg5','arg6'],List_Lower).
List_Lower = [arg1,arg2,arg3,arg4,arg5,arg6] ? ;
no

Upvotes: 1

Related Questions