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
7
votes
1 answer

Why "..." appears in my answer of matrix in Prolog

I made a little code for creating a matrix of coordinates (like a chessboard), it's the following: createMatrix(N,M,R) :- creaMatriu(N,M,A), reversed(R,A). creaMatriu(N,0,[T]) :- creafila(N,0,T),!. creaMatriu(N,M,[T|C]) :- creafila(N,M,T), M1 is…
Beldar
  • 73
  • 3
7
votes
2 answers

What's the difference between "false" and "no" in Prolog

I started to learn Prolog following the book Programming in Prolog: Using the ISO Standard. At page 7 of the intro to the language they made the assertion : "In Prolog the answer no is used to mean nothing unifies with the question. It is important…
Enrico Pirani
  • 1,387
  • 3
  • 13
  • 22
7
votes
1 answer

How to turn off "true" and "false" outputs in Prolog?

I would like to write a small text-based adventure game using Prolog (this might be a dumb idea but I am not here to discuss that). The only problem is that I can't manage to print text on screen without the "true" and "false" values to appear as…
gatsu
  • 237
  • 3
  • 8
7
votes
3 answers

Prolog list membership, multiple results returned

I have a standard procedure for determining membership of a list: member(X, [X|_]). member(X, [_|T]) :- member(X, T). What I don't understand is why when I pose the following query: ?- member(a,[a,b]). The result is True; False. I would have…
Justin
  • 322
  • 3
  • 13
6
votes
1 answer

Two stars in a Prolog list

what are the two stars in a list? [53, 5, 1, 53, 97, 115, 53, 50, 52, 121, 55, 56, 55, 97, 4, 1, 98, **] I tried searching but no success.
Jan
  • 61
  • 1
6
votes
4 answers

Automatic results showing?

How can I make SWI-Prolog interpreter to automatically do a semicolon? I have a lot of results (about 300) due to backtracking and I don't want to push semicolon for all of them. I do NOT want a list of all solutions, I only want not to push…
Javier
  • 801
  • 3
  • 10
  • 24
6
votes
2 answers

Make Prolog return one solution and stop showing the query option

I'm new to prolog, and am experimenting with how to get it to stop querying after it finds one answer. I'm using this code: member1(L,[L|_]). member1(L,[_|RS]) :- member1(L,RS),!. The result is: | ?-…
user3026297
  • 63
  • 1
  • 1
  • 3
5
votes
2 answers

SICStus Prolog: Find all solutions

Is there a way one can show all solutions and/or find how many there are in SICSTus prolog? For instance, the code below maybe used to solve the map colouring problem. :- use_module(library(clpfd)). solve_AUSTRALIA(WA,NT,Q,SA,NSW,V):- …
Enigma
  • 305
  • 2
  • 11
5
votes
3 answers

Prolog. In a query, how to put a condition on a variable that I do not want in the results?

Imagine that I have the following knowledge base which gives for each person his first name and his age. person(mary, 39). person(john, 24). person(sandy, 17). Now, I want to retrieve all the persons that are older than 20 years. Furthermore, I…
Mathieu Vidal
  • 53
  • 1
  • 5
4
votes
1 answer

Prolog tries to find multiple solutions when only one exists

I've made a basic predicate ascending/1 to check if a list is in ascending order, on https://swish.swi-prolog.org. ascending([]). ascending([_]). ascending([X, Y| T]) :- X =< Y, ascending([Y|T]). It shows the following if I query ?-…
user15072974
4
votes
2 answers

Order of unification in lists when using pipe(|)

I am having trouble trying to figure out in what order unification is done. I have the following query: [X, like | Z] = [I, Y, Prolog, language]. This gives me the following result: X = I, Z = [Prolog, language], Y = like. However, what I was…
Priyanshul Govil
  • 518
  • 5
  • 20
4
votes
1 answer

Naively assuming considered harmful: Prolog predicate with accumulator blows (global) stack, but naive version does not

I have tried a few versions of a simple predicate which pulls random values out of the extra-logical universe and puts them into a list. I assumed that the version with the accumulator would be be tail-call optimized, as nothing happens after…
David Tonhofer
  • 14,559
  • 5
  • 55
  • 51
4
votes
1 answer

How to send EOF on Prolog swipl REPL on Windows to close the pseudo user file?

I'm using the swipl.exe Prolog REPL on Windows and trying to use the user pseudo file opened with [user]. but I can't figure out the key shortcut to leave the pseudo file: c:\code>swipl.exe Welcome to SWI-Prolog (threaded, 64 bits, version 8.0.3) 1…
Carl Walsh
  • 6,100
  • 2
  • 46
  • 50
4
votes
1 answer

Understanding rules - false as answer

I am new in Prolog and I was just thinking that why this rule giving me false result after one true. likes(1,banana). likes(1,mango). test :- likes(1,banana),likes(1,mango). ?- test. true; false. I want to know the reason behind this false.
anilonwebs
  • 511
  • 1
  • 5
  • 13
4
votes
4 answers

How do return both a variable result and a true/false in Prolog?

It sounds silly, but lets say my predicate largest/2 returns the largest element in a list...the output should look like this: ?- largest([1,2,3,4,5], X). X = 5. false. I implemented largest, and it works like above except it doesn't output…
Eteocles
  • 41
  • 1
  • 2
1
2
3
10 11