Questions tagged [prolog-toplevel]

The "toplevel" or "top level loop" is Prolog's REPL.

The toplevel or top level loop is Prolog's REPL.

The toplevel differs from the read-eval-print loop in several ways:

Evaluation is performed incrementally. Typically, evaluation is only performed up to determining one answer, requiring user interaction to compute the next answer.

Printing an answer includes printing answer substitutions but may also include residual constraints.

155 questions
2
votes
1 answer

Don't understand Prolog result

I'm new to Prolog. I have this code: loves(vincent, mia). loves(marsellus,mia). jealous(X,Y):- loves(X,Z), loves(Y,Z). I queried jealous(vincent,W). But SWI-Prolog gives me W = vincent! Shouldn't it be W = marsellus?
user234159
  • 888
  • 3
  • 7
  • 19
2
votes
1 answer

Prolog, getting right answer in terminal, but wrong answer when running a program

Typing "prolog" in terminal gets: GNU Prolog 1.3.0 By Daniel Diaz Copyright (C) 1999-2007 Daniel Diaz | ?- Typing: | ?- member(2, [1,2,3]). Gets: true ? Then pressing enter gets: yes Typing: | ?- member(4, [1,2,3]). gets: no When i…
user3573388
  • 191
  • 1
  • 6
2
votes
0 answers

SWI-Prolog not labelling more than 9 variables

I want 10 variables with constraints, but Prolog only labels 9. Here's my code: :- use_module(library(clpfd)). colour(Regions) :- Regions = [A,B,C,D,E,F,G,H,I,J], Regions ins 1..10, all_distinct(Regions), labeling([], Regions). %%%…
dev
  • 2,474
  • 7
  • 29
  • 47
2
votes
1 answer

After the first answer, Prolog shows the error "char_code/2: Cannot represent due to 'character_code'"

In normal situation, we can use ";" to show the next answer if there is one. But if I do this, it shows me error: char_code/2: Cannot represent due to 'character_code' In stead of ";", I use "shift + ;", and prolog gives me a prompt Unknown…
2
votes
1 answer

Prolog: stop condition?

Here's a very trivial Prolog knowledge base: spouse(bill,cheryl). married(X,Y) :- spouse(X,Y). married(X,Y) :- spouse(Y,X). I ran the following queries. Note that sometimes the answer is the correct name (only), but other times the answer is the…
Bill Qualls
  • 397
  • 1
  • 7
  • 20
2
votes
3 answers

Prolog Backtracking On Finding A Solution And Returning False

I'm taking a crack at Prolog (using SWI-Prolog) and everything works like I want it to, i.e., the logic is calculated correctly and it finds the right solutions but the whole backtracking thing is screwing with me. Here's the code: tall(X) :-…
Nico
  • 3,471
  • 2
  • 29
  • 40
2
votes
1 answer

Change the Return response of Prolog

I am a novice at programming in prolog. I want to change the value returned by a prolog program such that it returns true / false instead of the standard yes or no. Consider a very simple example : E.g. simple.P node(1). isNode(X) : node(X) on the…
user1944347
1
vote
2 answers

prolog function returning memory locations instead of values

just started programming with prolog and I'm having a few issues. The function I have is supposed to take a value X and copy it N number of times into M. My function returns a list of N number of memory locations. Here's the code, any…
Dommol
  • 191
  • 1
  • 17
1
vote
1 answer

Learn prolog exercise 2.3

Im going thru the learn prolog website to try to learn some prolog and are trying to under stand exercise 2.3. I guess every call to word() goes one down into some sort of stack or so and that would explain why it seems to change the words from the…
Buzzzz
  • 887
  • 3
  • 11
  • 18
1
vote
2 answers

Why Prolog gives 'false' at the end of a simple query?

I am just beginning to learn Prolog: % Doors door(kitchen, office). connect(X, Y) :- door(X, Y). connect(X, Y) :- door(Y, X). Now, when I consult: ?- connect(kitchen, office). true ; false. ?- connect(office, kitchen). true. ?- Why in the…
Tom B.
  • 21
  • 3
1
vote
2 answers

Prolog Flow Free solver

I'm completely new to Prolog and working on a homework assignment My program is supposed to solve flow free problem using depth first, I don't need the whole code for it as its what supposed to do but I need to know how to think to solve it or what…
1
vote
1 answer

In Prolog why does this query return this particular result

?- assert(p(a)),assert(p(b)),p(X). X = a yes Whats the effect of this query and why does it return this particular result?
General_9
  • 2,249
  • 4
  • 28
  • 46
1
vote
1 answer

How add finitely failed branches to a Prolog visualizer?

Assume we want to visualize this Prolog execution. No goals from the fidschi islands, or something else exotic assumed, only good old SLDNF with the default selection rule: p(a). p(b). ?- \+ p(c). Yes But we have only a Prolog visualizer that can…
user502187
1
vote
1 answer

Does Prolog's toplevel use the wrong operator when printing results?

I have been staring at Prolog toplevel results like these for some time now: ?- reverse([X,Y,Z],[Y,Z,Y]). X = Y, Y = Z. And it just occurred to me: Shouldn't it say ?- reverse([X,Y,Z],[Y,Z,Y]). X == Y, Y == Z. Because = is unification, and == is…
David Tonhofer
  • 14,559
  • 5
  • 55
  • 51
1
vote
2 answers

When does Prolog prompts 'yes' and when does it says 'true'

I wrote the following knowledge base in Prolog: likes(yamini,chocolate). likes(anuj,apple). likes(yamini,book). likes(john,book). likes(john,france). Now, when I consult the above file and try the following commands: | ?- likes(anuj,apple). …
yamini goel
  • 519
  • 2
  • 10
  • 23