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

Prolog - Return result instead of printing in algorithm

I know there is technically no 'return' in Prolog but I did not know how to formulate the question otherwise. I found some sample code of an algorithm for finding routes between metro stations. It works well, however it is supposed to just print the…
skamsie
  • 2,614
  • 5
  • 36
  • 48
4
votes
1 answer

How to expand a resulting list in SWI-Prolog?

?- length(L,25). L = [_G245, _G248, _G251, _G254, _G257, _G260, _G263, _G266, _G 269|...]. If I use write(L) following the length predicate then the interpreter prints the list twice, one expanded and the other not.
TheOne
  • 10,819
  • 20
  • 81
  • 119
4
votes
2 answers

What does "?-" mean in Prolog?

What does ?- mean in Prolog? for example: ?- consult(solve)
hpn
  • 2,222
  • 2
  • 16
  • 23
3
votes
2 answers

how to handle prolog lists?

I have the predicate m(L,L) and I want it to return the list that it takes. The code is this : m([],[]). m([H|T],[H|L]) :- m(T,L). When I try to use it with this example : m([1,2,3,4,5,6,7,8,9,10],L) I get this as an answer : L = [1, 2, 3, 4, 5,…
3
votes
2 answers

SWI-Prolog reporting wrong answer with bitshifts CLPFD

I encountered this in a much larger codebase, but reduced it down to a minimal reproducible example. This is some code for an assembler: :- use_module(library(clpfd)). bigconst(X) :- X #=< 0x3FF, X #>= 0. asm(instruction('ADD', [A]), R) :- …
redfast00
  • 1,363
  • 1
  • 12
  • 23
3
votes
1 answer

How to change the order in which variables are printed in prolog?

This is a homework problem, but I just need a simple question answered. I am supposed to print all the possible ways a knight can jump on a chess board from it's position. I am getting the correct numbers but I don't seem to get the correct output…
David Andvett
  • 133
  • 4
  • 10
3
votes
1 answer

less-like pager for (swi) prolog

The typical workflow in unix is to use a pipeline of filters ending up with a pager such as less. E.g. (omitting arguments) grep | sed | awk | less Now, one of the typical workflows in the swi-prolog's command line is asking it to give the set of…
Alexander Gorshenev
  • 2,769
  • 18
  • 33
3
votes
1 answer

Write queries results into a file in prolog

Here is my prolog database code. :- dynamic myTable/2. init :- removeAll, asserta(myTable('avalue', 'another value')), asserta(myTable('avalue1', 'another value 1')), asserta(myTable('avalue2', 'another value 2')), …
sasha199568
  • 1,143
  • 1
  • 11
  • 33
3
votes
1 answer

Prolog, on start executing write something

I want to display a string on terminal when the user executes it. But, I want to do this without calling any predicate. For example, if the code is like this: print_sth(String):-write(String). it will print some string only if I make an explicit…
Dionis Beqiraj
  • 737
  • 1
  • 8
  • 31
3
votes
1 answer

Prolog backtracking policy

SWI-Prolog, version 6.6.6. Consider the following facts: p(a, a). p(a, b). It results in the following answer: ?- p(a, a). true ; false. But if I slightly change the data: p(a, a). p(b, a). I get a slightly different answer... ?- p(a,…
lledr
  • 537
  • 1
  • 3
  • 12
3
votes
1 answer

Redirecting standard output stream

How do I write the output of listing/0 in SWI-Prolog REPL to a file ? ?- listing > file.txt.
sten
  • 7,028
  • 9
  • 41
  • 63
3
votes
1 answer

Undefined procedure error in prolog SWI

Running prolog SWI on windows 8 for the first time. this is my program (.pl) file, very basic just with 3 facts: (I'm a complete prolog beginner) hello. a. b. When I load it (consult) in prolog-SWI, and work with the program, I get this error in my…
user3256369
  • 135
  • 1
  • 9
3
votes
2 answers

Question mark in SWI-Prolog - nondeterministic functor

I've just tried to implement absolute function in Prolog and I've got some strange behavior. My code was: absval(X, RESULT) :- X >= 0, RESULT is X. absval(X, RESULT) :- X < 0, RESULT is -X. And when I try in SWI-Prolog absval(-2,X). I get X =…
pt12lol
  • 2,332
  • 1
  • 22
  • 48
3
votes
1 answer

Reload imported modules

The "problem" I am facing is that if I use the SWI-Prolog module system, defining modules and using them in other modules, if an imported module changes SWI-Prolog does not take it in consideration when loading the importing module. For example: %…
user1812457
3
votes
2 answers

ERROR: Undefined procedure: (:-)/2

I'm new in Prolog , I am trying to set rule on SWI-Prolog shell e.g - listensToMusic(X) :- happy(X). But it prompts - ERROR: Undefined procedure: (:-)/2 I use SWI-Prolog version 6.2.6
URL87
  • 10,667
  • 35
  • 107
  • 174
1 2
3
10 11