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
33
votes
5 answers

SWI-Prolog - show long list

I'm using SWI-Prolog and I'm trying to print a list but if the list has more than 9 items - it look like that - [1, 15, 8, 22, 5, 19, 12, 25, 3|...] is there a way to show the whole list?
TamarG
  • 3,522
  • 12
  • 44
  • 74
31
votes
2 answers

Why is this prolog query both true and false?

My SWI-Prolog knowledge base contains the following two facts: f(a,b). f(a,c). Now if I pose the query ?- f(a,c). true. But ?- f(a,b). true ; false. Why is f(a,b) both true and false? This also happens when there are three facts in the KB. If…
del
  • 311
  • 1
  • 3
  • 3
27
votes
1 answer

Definition of Reflexive Transitive Closure

Many predicates essentially use some form of transitive closure, only to discover that termination has to be addressed too. Why not solve this once and forever with closure0/3: :- meta_predicate closure0(2,?,?). :- meta_predicate closure(2,?,?). :-…
false
  • 10,264
  • 13
  • 101
  • 209
14
votes
2 answers

Prolog gives error "undefined procedure" when trying to use :-

I'm using SWI-Prolog on Windows and am getting the following error: 14 ?- parent(X, Y) :- child(Y, X). ERROR: toplevel: Undefined procedure: (:-)/2 (DWIM could not correct) I'm not entirely sure what's going on, as this worked last week and I am…
Ross
  • 46,186
  • 39
  • 120
  • 173
14
votes
3 answers

Implementing "last" in Prolog

I am trying to get a feel for Prolog programming by going through Ulle Endriss' lecture notes. When my solution to an exercise does not behave as expected, I find it difficult to give a good explanation. I think this has to do with my shaky…
Michael Wijaya
  • 377
  • 2
  • 9
13
votes
1 answer

Prolog anonymous variable

Here is what I have understood about Prolog variables. A single underscore stands for anonymous variable, which is like a new variable each time it occurs. A variable name starting with underscore like _W is not an anonymous variable. Or, the…
Gurkan E.
  • 205
  • 1
  • 2
  • 7
12
votes
1 answer

Why does SWI-Prolog only give me the first answer?

I'm new to Prolog. I'm just trying simple examples to learn. I have this .pl file with these lines: parent(pam,bob). parent(tom,bob). parent(tom,lio). parent(bob,ann). parent(bob,pat). parent(pat,jim). After consulting and testing, it only shows…
Sahar Alsadah
  • 2,580
  • 3
  • 19
  • 25
12
votes
2 answers

Prolog: Making a procedure to print Hello World

I want to load this simple something into my Editor: Write:-repeat,write("hi"),nl,fail. So that it prints "hi". What should I do? I'm currently trying to do File->New and Saving a file named Write into E:\Program Files\pl\xpce\prolog\lib When doing…
andandandand
  • 21,946
  • 60
  • 170
  • 271
8
votes
3 answers

Creating and working with an explicit list vs enumeration through fail

I come up against this all the time, and I'm never sure which way to attack it. Below are two methods for processing some season facts. What I'm trying to work out is whether to use method 1 or 2, and what are the pros and cons of each, especially…
magus
  • 1,347
  • 7
  • 13
8
votes
3 answers

How to see all of the answers in SWI-Prolog without pressing spacebar?

Simple example: ?- between(1,10,X). X = 1 ; X = 2 ; X = 3 ; X = 4 ; X = 5 ; X = 6 ; X = 7 ; X = 8 ; X = 9 ; X = 10. When this is done using SWI-Prolog using the REPL to see the next answer the spacebar has to be pressed. How can all of the results…
Guy Coder
  • 24,501
  • 8
  • 71
  • 136
8
votes
2 answers

Get multiple solutions in SWI-Prolog using toplevel

I'm beginner in SWI-Prolog (but have some experience in Borland Prolog), and I've faced with a strange behavior for the following test code: test(10). test(1). It is expected for query ?-test(A) to get 2 solutions, something like A = 10; A = 1.…
Spectorsky
  • 608
  • 4
  • 23
8
votes
3 answers

Prolog nth1 anonymous variables

I have a List with Integers and anonymous variables and I try to find the index of a special values. Problem is as soon I'm using nth1/3 to find the indices Prolog assigns values to the anonymous variables and therefore I find way too indices. …
Ben373
  • 951
  • 7
  • 16
8
votes
5 answers

SWI-Prolog how to show entire answer (list)?

I'm trying to convert a string to a list of ascii-codes like so: 7 ?- string_to_list("I'm a big blue banana in space!", C). C = [73, 39, 109, 32, 97, 32, 98, 105, 103|...]. 8 ?- This doesn't give me the entire list as you can see, but I need…
Mossmyr
  • 909
  • 2
  • 10
  • 26
7
votes
2 answers

Defining predicates in SICStus Prolog / SWI-Prolog REPL

I am reading http://cs.union.edu/~striegnk/learn-prolog-now/html/node3.html#subsec.l1.kb1, but I am having trouble running the following predicate: SICStus 4.0.1 (x86-win32-nt-4): Tue May 15 21:17:49 WEST 2007 | ?- woman(mia). ! Existence error in…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
7
votes
2 answers

yes/no return in PROLOG query

I'm just learning PROLOG and I'm having a difficult time understanding why the queries that I'm performing result in an ending of 'yes/no'. Here's my…
1
2 3
10 11