0
votes

I want to use a predicate to find the sublist meet the requirement that contains at least one atomic(not variable).

contain_atomic([[a,c,e],[a,e,D],[D,A,E]],X).
X = [[a,c,e],[a,e,D]].

So far, I can only turn those sublist whose elements are all variables to empty.

all_variable([],[]).
all_variable([A|B],[]):-
    \+atomic(A),
    all_variable(B,[]).

And what's next? Am I close to success?

1
"[...] to find the sublist meet these two [...]" -- I don't understand this formulation. Do you mean "find the sublist that meet" or "find if the sublist meet"?aioobe
find the sublist that meet those two requirement. Or maybe one that find the sublist contains at least one atomic(not variable). It's the same meaning.Love programming

1 Answers

1
votes

I recommend you write a predicate that states what must hold for a single sublist to be included in the result (I leave this task as an easy exercise for your concrete case):

your_property(Sublist) :-
    ...

Then, use include/3 to filter all sublists that satisfy this property:

include(your_property, Lists0, Lists)

Always (at least) consider using include/3 and exclude/3 when filtering lists, because they simplify the task by only necessitating a description of the property for a single element.