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
3 answers

How to use ground/1?

I'm a complete beginner with Prolog and I wanted to know how to use ground/1. At the moment I have this code: intertwine([], [], []). intertwine([E|Es], Fs, [E|Gs]) :- intertwine(Es, Fs, Gs). intertwine(Es, [F|Fs], [F|Gs]) :- intertwine(Es, Fs,…
user1008820
  • 181
  • 1
  • 2
  • 9
2
votes
1 answer

PROLOG rule stops after finding first match

I am completely new to Prolog and self teaching out of interest. Very sorry to bring such a basic question to you, but the Manuals (SWI-Prolog) don't seem to clarify why I see this behaviour. I am playing around with basic predicates with multiple…
Error42
  • 33
  • 3
2
votes
2 answers

Prolog, predicate returns the correct result, but also false?

I found that for most of my predicates, prolog finds multiple solutions, with one of them being the correct result, the other is 'false.' To demontrate: %finds the last element of list, or false if empty. last([H|L], More):- last(L,…
goldenotaste
  • 302
  • 2
  • 11
2
votes
1 answer

(gnu) Prolog statement with "or" simple example

I struggle with a rather simple GNU Prolog example: I have a file (test.pl) cat(muki). dog(roti). frog(frogi). animal(X) :- dog(X). animal(X) :- cat(X). When testing it: Importing via ['test.pl'] animal(frogi) returns no, as expected animal(muki)…
lubro
  • 326
  • 3
  • 9
2
votes
1 answer

How to list more than 1 output on prolog query?

Imagine my siblings, my cousins and me and our total count is 10. So i write this code and when i run it, it just give me 1 output. How can i print all the X values(names) on this query. And if possible how can i change what name comes first or how…
Utku
  • 21
  • 3
2
votes
2 answers

Why `X=1,X=1.` prints `X=1` instead of `true`

I'm learning the basics of Prolog and I was wondering why the following line prints X = 1 instead of true? ?- X=1,1=X. X = 1. -- The first X=1 in my command is an assignment, and the second one will be a check of equality.
Stav Alfi
  • 13,139
  • 23
  • 99
  • 171
2
votes
1 answer

Expanding Prolog clauses without parameters

I am writing a program that transforms other programs by expanding predicates. I usually do this using clause/2, but it doesn't always expand a predicate if it has no parameters: :- set_prolog_flag('double_quotes','chars'). :-…
Anderson Green
  • 30,230
  • 67
  • 195
  • 328
2
votes
1 answer

swi-prolog doesn't stop after first true with disjunction (or)

I (Prolog absolute beginner) try to make sense out of prolog. Here's a Santa example in…
Kurt Sys
  • 31
  • 6
2
votes
0 answers

Why does Prolog rule sometimes return False with similar inputs?

I cannot understand why false is returned for jordan but not for china: When I query: countries_visited(jordan, X). I get a return of amman and false. But when I query countries_visited(china, X). I get a return of beijing and…
benji247
  • 21
  • 2
2
votes
3 answers

For length/2 how to add human readable variable names

How can human readable variable names be displayed for system generated variable names? As a simple example: ?- length(Ls,N). Ls = [], N = 0 ; Ls = [_5112], N = 1 ; Ls = [_5112, _5118], N = 2 ; Ls = [_5112, _5118, _5124], N = 3 would be nicer as ?-…
Guy Coder
  • 24,501
  • 8
  • 71
  • 136
2
votes
3 answers

PROLOG - How to round decimals of floating point numbers?

I have this line in the knowledge base: height(Hipot,Y) :- Y is sin(pi/6)*Hipot. which calculates one of the cathetus of a right triangle. When asking Prolog for the value of Y, that is the cathetus, I get an inaccurate number: ?- height(1,Y). Y =…
netotz
  • 193
  • 1
  • 4
  • 12
2
votes
1 answer

Exiting SICStus - Command Line

Is there any other way of exiting SICStus on Command Line without having to press ^C plus e after (I can't always get to this "help menu" with ^C). The "real" question is if it exists a command like :exit or !quit, similar to other command line…
zediogoviana
  • 305
  • 3
  • 14
2
votes
1 answer

Why is my delete_all method returning a list with a random memory location in prolog?

So, I'm trying to delete all elements where Y is a. It seems to work but the problem I'm getting is that it is returning the wrong thing. This the result of my return. Result = [b, c, d|_G1355] This is my code so…
christian
  • 105
  • 6
2
votes
1 answer

Cryptarithmetic operation

I was trying to write Prolog code for "SEND MODE MONEY". So far, I got the following: :- use_module(library(clpfd)). puzzle([S,E,N,D] + [M,O,R,E] = [M,O,N,E,Y]) :- Vars = [S,E,N,D,M,O,R,Y], Vars ins 0..9, all_different(Vars), S*1000…
Pramod
  • 47
  • 1
  • 7
2
votes
2 answers

How to write the evaluation of a big factorial to a file in Prolog?

I am trying to export the evaluation of the factorial of 500000 to a file, for which I compile the following program: fact(N, NF) :- fact(1, N, 1, NF). fact(X, X, F, F) :- !. fact(X, N, FX, F) :- X1 is X + 1, FX1 is FX * X1, …