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

Outputting prolog in Mac

I have a problem using prolog on a Mac, I figured out how to run it using SWI-Prolog but when I run it, it gives an error and does not give the expected output Expected output: homer,…
cbotnav
  • 21
  • 4
1
vote
0 answers

Label variables in Prolog

I'm writing a Prolog predicate that retuns a list of variables. Right now the list of variables are _ (underscored) variables, for example: Xs = [_2654, _2690], . . . And I would like to label these variables with an increasing index, for…
chendoy
  • 155
  • 1
  • 2
  • 12
1
vote
1 answer

how to exit from swipl to bash?

stav> swipl Welcome to SWI-Prolog (threaded, 64 bits, version 8.0.3) SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software. Please run ?- license. for legal details. For online help and background, visit http://www.swi-prolog.org For…
Stav Alfi
  • 13,139
  • 23
  • 99
  • 171
1
vote
1 answer

When does Prolog break lines?

Consider the following example program in Prolog: p(0). p(1). b1(T) :- T = tri(X, Y, Z), p(X), p(Y), c(T), !, p(Z). c(tri(X, X, _Z)). SWI Prolog gives some interesting answers for certain queries:\ ?- b1(tri(0, Y, Z)). Y = Z, Z = 0 ; Y = 0, Z…
user4385532
1
vote
1 answer

up,down,left and right cannot be used when using SWI-Prolog in terminal

I met a problem when I use prolog(swipl), after I type swipl in the terminal, code like '^[[A^[[B^[[D^[[C' shows when I press up, down, left, and right on my keyboard. Could somebody explain why? and how to fix it. Thanks in advance!
Jasper Zhou
  • 449
  • 1
  • 5
  • 13
1
vote
2 answers

Why is the behaviour of SWI-Prolog seemingly inconsistent?

Trying to understand the cut-fail combination in Prolog, I found the following example and started to play with it: enjoys(vincent,X) :- big_kahuna_burger(X),!,fail. enjoys(vincent,X) :- burger(X). burger(X) :- big_kahuna_burger(X).…
BarbuDorel
  • 193
  • 1
  • 1
  • 5
1
vote
2 answers

Prolog Output Gives False After True

I have a prolog program to represent the flights between two states with their costs. My program is this: flight(newyork,washington,7). %its mean that there is a flight between both washington and newyork, newyork and washington with cost 7.…
1
vote
1 answer

Prolog goal with multiple results

spec(comp1, pc, 32). /* Fact 1 */ spec(comp2, mac, 128). /* Fact 2 */ spec(comp3, pc, 64). /* Fact 3 */ runs(pc, movie_edit, 96). …
Hamza
  • 157
  • 2
  • 12
1
vote
1 answer

Why does Prolog predicate member/2 print an extra whitespace in output?

I really don't understand why Prolog prints a single whitespace after the member/2 predicate only. The following is the text from my console. ?- member(1, [1, 2, 3]). true . ?- string("why"). true. This is really driving me crazy!
Jimbo
  • 444
  • 2
  • 7
  • 22
1
vote
1 answer

list truncation: set_prolog_flag(toplevel_print_options, [max_depth(100)]) having no effect

All the questions regarding how to disable list truncation had the answer to use some variantion of this: ?- set_prolog_flag(toplevel_print_options, [quoted(true), portray(true), max_depth(100), priority(699)]). For me this does not work, see…
lo tolmencre
  • 3,804
  • 3
  • 30
  • 60
1
vote
0 answers

Prolog permutation type_error

Ok I am trying to use the permutation function and i get a weird type error exception. permutation(X,[1,2,3]). X = [1,2,3] When I type a semicolon I get the following error: ERROR: Type error: 'character_code' expected, found '-1' (an…
1
vote
1 answer

Type error: `character_code' expected with prolog

I am new to prolog. I was writing a code with Goldbach’s Conjecture problem which I have to list all possible groups of one even number. I found a code like this: is_prime(2). is_prime(3). is_prime(P) :- integer(P), P > 3, P mod 2 =\= 0, \+…
1
vote
1 answer

Prolog, Printing variable instead of actual answer, works for different answer but not for duplicates

singleShiftDataGen([Name1,Name2,Name3,Name4],Shifts, PersonData1,PersonData2,PersonData3,PersonData4):- find(Name1, Shifts, PersonData1), find(Name2, Shifts, PersonData2), find(Name3, Shifts, PersonData3), find(Name4, Shifts,…
1
vote
2 answers

Prolog not showing full list of answer

When I run query human(Who). on the below .pl file human(ann). human(george). human(mike). I only get back Who = ann . Instead of Who = ann ; Who = george ; Who = mike. Am using prolog 6.6.6. How do I get it to show the full list?
Gavin
  • 2,784
  • 6
  • 41
  • 78
1
vote
1 answer

Query returning true/false

I recently started learning Prolog and have come across an issue. The following has been loaded into Prolog: likes(john, apple). likes(john, pear). likes(john, grapes). likes(bill, mango). likes(bill, apple). I am writing a predicate all_like(What,…
user2268507