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

Goal (directive) failed: user:main Prolog swi

may(_,[],[]). may(num(U),[est(C1,N1,NT1)|T1],[est(C1,N1,NT1)|T2]):- U =< NT1, may(num(U),T1,T2). min(_,[],[]). min(num(U),[est(C2,N2,NT2)|T3],[est(C2,N2,NT2)|T4]):- U > NT2, min(num(U),T3,T4). main:- U is 2.0, mayores(num(U), …
2
votes
1 answer

PROLOG result vs true

I have the next code in a file called "testing.pl": fact(1). fact(2). fact(3). funcA(X) :- funcB(X). funcB(X) :- fact(X). testing :- funcA(_X). Then, in SWI-Prolog interpreter I query funcA(X). and the output is: X = 1 ; X = 2 ; X = 3. But,…
Haddex
  • 38
  • 1
  • 8
2
votes
1 answer

Why the inconsistent responses from swipl?

I'd like to understand why the interaction with swipl appears to be inconsistent. Here's a typical example. Suppose I have consulted a knowledgebase that includes the following definitions: acc_max([H|T], A, Max) :- H > A, acc_max(T, H,…
kjo
  • 33,683
  • 52
  • 148
  • 265
2
votes
2 answers

How can I show the intermediate steps in Prolog of this graph pathfinder?

I have created this knowledge base in Prolog, which reflects a bus company wth busses going from and to places, leaving and arriving at set times: connection(kerkrade, heerlen, 1100, 1200). connection(kerkrade, bleijerheide, 1100,…
Zimano
  • 1,870
  • 2
  • 23
  • 41
2
votes
2 answers

Getting "true; false" set of two answers for a set of rules

first off thanks for helping. I am writing a prolog program describing family relationships, including all versions of in-laws. The logic is all there, what I need help with is some prolog problems as I am not very experienced with it. I am trying…
cliff259
  • 114
  • 2
  • 9
2
votes
3 answers

Prolog: get all possible values of a variable

I'm Following Prolog Tutorial 2.1. Program adjacent(1, 2). adjacent(1, 3). adjacent(1, 4). main:- adjacent(1, R), write(R). prints 2. But it supposes to print a list of possible values according to the tutorial: ?- adjacent(1,2). yes ?-…
Rahn
  • 4,787
  • 4
  • 31
  • 57
2
votes
2 answers

Is there a way to write a length/1 predicate using write/1 to print result?

I have an assigment for school, started learning Prolog recently. This is the exercise (pretty straightforward): Write a program in Prolog to find a length of a given list. For example, length([a, b, c, d, e]). should print 5 I really have no…
Kes
  • 47
  • 4
2
votes
1 answer

Get further solutions to a query

I have assert(user(anna)). assert(user(tom)). but when I query ?- user(X). I only get X = anna. Shouldn't I get another line saying X = tom as well?
Nevvea
  • 67
  • 4
2
votes
1 answer

How do you change 'write_options' in prolog to print a long list?

By default, SICStus Prolog will only display the first ten elements of a list (after which it shows ...). How do you make Prolog display all the elements of a long list? I have tried: set_prolog_flag(toplevel_print_options, [quoted(true),…
hassapikos
  • 59
  • 1
  • 2
  • 10
2
votes
1 answer

Success and failure when querying the database

So I'm stuck on an exercise that I've been working on. I have the following facts: sd(appleseed0, appleseed1). sd(appleseed0, apple1). sd(appleseed1, apple1). sd(appleseed2, apple1). sd(appleseed0, apple2). sd(appleseed1, apple2). sd(appleseed2,…
Joffrey Baratheon
  • 494
  • 1
  • 5
  • 19
2
votes
1 answer

Accepting 2 different colors, but not the same colors

I'm trying out an exercise where I have to write the predicate, colors/2 (or colors(C1,C2) :- ...) that runs like the following: ?- colors(red,blue). true. ?- colors(red,red). false. ?- colors(blue,blue). false. So, essentially, I have to write my…
Jubl
  • 247
  • 3
  • 14
2
votes
1 answer

Predicate Prints Out "Unexpected" false

I am trying to write a predicate, likes/2, in a manner where it runs like the following: ?- likes(A,alan). A = lindsay ; A = chloe ; A = cheyanne ; A = britney ; Here is how I am tackling the problem: % Define your…
The Hound
  • 81
  • 8
2
votes
1 answer

Prolog compiler return error

I have this hypothetical program to check if a path exists from point A to B. /*city rules*/ edge(phx, tuc). edge(tuc, ccg). edge(ccg, sf). connected(C1, C2) :- edge(C1, C2). connected(C1, C2) :- edge(C1, X), connected(X, C2). the…
ryan
  • 625
  • 3
  • 10
  • 23
2
votes
1 answer

Prolog list not printing all the elements on console

I am using SWI-PROLOG version 6.6.6 I want to print all the attributes of a particular predicate type. I have a predicate called law with arity 2. Some of the facts are law(borrow,'To borrow Money on the credit of the United…
ronilp
  • 455
  • 2
  • 9
  • 25
2
votes
1 answer

swi-prolog forall function doesn't work

I have predicate superclass('Horde', 'Blood Elf'). superclass('Horde', 'Orc'). element('Blood Elf', ['Paladin', 'Priest','Mage','Warlock','Death Knight','Rogue']). element('Orc', ['Warrior', 'Shaman','Warlock','Death…
defusioner
  • 47
  • 5