Filtering elements from a list based on conditions in prolog?

Exclude and include (which you really want) take a predicate name as their first argument.

Exclude and include (which you really want) take a predicate name as their first argument: goodroutes(From, To, Routes) :- allroutes(From, To, All), include(goodroute, All, Routes). Though it would be more efficient to filter out the bad routes during the call to findall, since then you wouldn't have to build the set of all routes first: goodroutes(From, To, Routes) :- findall(Route, (pathfrom(From, To, Route), goodroute(Route)), Routes). Note the ( , ); we're giving findall a conjunction of two goals as its second argument.

Thanks. The one using findall looks more efficient than the one with include. And in findall(Route, (pathfrom(From, To, Route), goodroute(Route)), Routes).

, we can use as many goals for it to match right? If I have more condition I need to meet, I just do findall(Route, (pathfrom(From, To, Route), goodroute(Route),another_condition), Routes). Right?

– RBK Jul 27 at 20:43 @RBK: that's right, and it's also more portable. Include is nice if you get a fully constructed list as input, but filtering early can save a lot of time in the end. – larsmans Jul 27 at 21:17.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions