Questions tagged [prolog-findall]

findall/3 is a built-in predicate of ISO Prolog.

66 questions
2
votes
2 answers

Logically Handling Lists

I have a large number of facts within my program, listing developers and designers in a company, as well as previous projects, like so.. % project(Project Name,Year) project(efnet, 2007). % designer(Project Name, Name, Role) designer(efnet,…
AlexT
  • 561
  • 1
  • 8
  • 22
2
votes
1 answer

Can you use clpfd to implement a coverage algorithm?

Say I want to find the set of features/attributes that differentiate two classes in a simple matching manner can I use clpfd in prolog to do this? c_s_mining(Features,Value):- Features = [F1,F2,F3,F4], Features ins 0..1, ExampleA =…
user27815
  • 4,767
  • 14
  • 28
2
votes
2 answers

Alternative to findall

I'm trying to create an alternative to findall in Prolog. What I have is: solutions(A,T,S) :- T, assert(temp(A)), fail. solutions(A,T,S) :- obtain([],S). obtain(X,S) :- retract(temp(A)), obtain([A|X],S). obtain(S,S). This is…
PablodeAcero
  • 399
  • 8
  • 20
2
votes
2 answers

why findall/3 in swi-prolog ignores variable binding?

The following codes give these results: ?- X = a, findall(Element, ( member(Z, [a,b,c]), Element = Z:X ), Set). X = a, Set = [a:a, b:a, c:a]. But when I want that all elements will share the same unbound variable (instead of a), then things are…
Fibo Kowalsky
  • 1,198
  • 12
  • 23
2
votes
1 answer

Finding all matches to a query without using findall/3 in Prolog

I am given a database and I am querying the database with a predicate findmin(A,B,course(X,Y)):- course(X,Y),X >= A,Y =< B. I have my database like, course(a1,b1). course(a2,b2). course(a3,b3). ... Now instead of using standard…
2
votes
1 answer

findall/3 returns an empty list instead of solutions

I use GNU Prolog to solve a problem. I have defined the following predicate : % P is the product of X and Y produit(X,Y,P) :- between(2,200,X), between(2,200,Y), X #<# Y, X*Y #=# P. % S is the sum of X and Y somme(X,Y,S) :- …
Saroupille
  • 609
  • 8
  • 14
2
votes
1 answer

Findall with lists for Pacman netlogo game

I'm a beginner at prolog and I'm trying to make pacman move by itself using netlogo and prolog. So this is part of my code: walkfront(_,_,_,_,_,_,Pacman,DirP,Lab,Ghost,_,Pellet,_,_,Decision) :- findall(Dir, (…
Niammi
  • 76
  • 1
  • 7
1
vote
1 answer

Why this predicate is written in this way?

I am having a hard time to understand why the second predicate of findall is written as this instead of collect_found([],L) directly. :- dynamic found/1. findall(X, G, _) :- asserta(found(mark)), call(G), asserta(found(result(X))), …
1
vote
2 answers

PROLOG, Is it possible to collect all result from a predicate to a list, without using built in predicates, such as bagof or findall

If for example, I have a Prolog predicate like a(A, B). Is it possible to collect, given a value of A, is it possible to collect all values of B that succeeds the predicate a, into a list, without using built in predicates such as bagof/3 or…
Eason51
  • 17
  • 4
1
vote
1 answer

Fitltering in findall

I have rule: best_fit(Team, Enemies, Result, List) :- findall((H, E), score(H, Enemies, Team, E), List), where score definition is: score(Hero, Enemies, Team, Result) :- hero(Hero), ... I would like to find only that (H,E) where H is not…
Marcin Majewski
  • 1,007
  • 1
  • 15
  • 30
1
vote
1 answer

How to inline a goal with findall/3, (use just one predicate)?

I have a knowledgebase that looks something like this fact1(1, _, a, _, _). fact1(2, _, c, _, _). fact1(3, _, d, _, _). fact1(4, _, f, _, _). fact2(_, 1, b, _, _). fact2(_, 2, c, _, _). fact2(_, 4, e, _, _). For every fact1 & fact2, where (in…
HappyHippo
  • 152
  • 3
  • 11
1
vote
3 answers

Avoid findall overflow with n-fractions problem

I am trying to print all solutions of the n-fractions problem for n=4: :- lib(ic). fractions(Digits) :- Digits = [A,B,C,D,E,F,G,H,I,J,K,L], Digits #:: 1..9, ic:alldifferent(Digits), X #= 10*B+C, Y #= 10*E+F, Z #= 10*H+I, V…
Codefather
  • 27
  • 1
  • 9
1
vote
2 answers

Correct use of findall/3, especially the first template argument

i know there is a build-in function findall/3 in prolog, and im trying to find the total numbers of hours(Thrs) and store them in a list, then sum the list up. but it doesnt work for me. here is my code: totalLecHrs(LN,THrs) :- …
Tom
  • 19
  • 2
  • 2
  • 3
1
vote
1 answer

findall(X,condition,List) list is filled with pointers and not real objects

I am trying to get a list full of objects from the database that fit my condition. Here is my…
Tomer
  • 531
  • 7
  • 19
1
vote
0 answers

Prolog findall infinite loop

I have a predicate that asserts things. When I use a findall it goes into an infinite loop. assertarv([N|R]):- assert(veiculos_troncos(N)), assertarv(R). assertarv([]). When I use findall(A,veiculos_troncos(A),NTr) , after having used the…
user3636673