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

How to sort output in Prolog?

I have the following predicate: soln(L,M,O,R,S,V) :- permutation([L,M,O,R,S,V],[1,2,3,4,5,6]), R=\=S+1, R=\=S-1, M=:=L+1, O>M, O
Brennan Vincent
  • 10,736
  • 9
  • 32
  • 54
0
votes
1 answer

Finding out which rule fired in a prolog file

I have a prolog file that classifies a given predicate bongard(A, X) with given background facts. Snippet of the rules: bongard(A,[neg]) :- triangle(A,C), \+ in(A,C,D), !. bongard(A,[neg]) :- \+ triangle(A,C), !. ... I am executing this program…
xrdty
  • 886
  • 2
  • 10
  • 22
0
votes
0 answers

How to open file loaded via REPL in prolog?

In prolog, or at least in SWI-Prolog, you can load a file typing [filename]. or ['filename.ext']. or [path/to/file]. or ['path/to/file.ext']. However, I want to preprocess the file going to be loaded and therefore I need the content of above…
user3389669
  • 799
  • 6
  • 20
0
votes
1 answer

Recursive Prolog function with extraneous false solution

I'm struggling to understand why fib([1,2],F) finds a second solution, false, with the following clauses and rules: fib([A,B|C],F) :- fib([B|C],S), fib(C,T), F is (S+T). fib([A],1). fib([],0). According to my logical analysis of…
Måns Nilsson
  • 431
  • 1
  • 4
  • 16
0
votes
1 answer

Prolog: How to adjust the maximum length of lists shown in a trace?

Feel free to cut immediately past the first two paragraphs, they are mostly waffle explaining the situation. I'm working on a task for my University course, while I don't want any help solving the actual problem (I feel like that's "cheating" as it…
Shefeto
  • 178
  • 1
  • 10
0
votes
0 answers

Prolog hide returned predicate value

Lets say i have simple hello world code hworld:-writeln('hello world'). This code always returns something like this: hello world true. As far as i understand prolog, it returns either variable value (of X i.e. fact(5,X).) or true/false, if…
Smarty77
  • 1,208
  • 3
  • 15
  • 30
0
votes
1 answer

prolog in math - searching the level of node in prolog

Assuming here is a binary search tree, and given the rule that above(X,Y) - X is directly above Y. Also I created the rule root(X) - X has no parent. Then, I was trying to figure out what the depth of node in this tree. Assume the root node of tree…
user1234567
  • 57
  • 2
  • 11
0
votes
1 answer

I am struggling to connect these three rules together

I'm having issues connecting the following three rules together. countingCombo([H|T], Sequence2) :- fact1(H, Sequence), append(Sequence, Sequence2, Sequence3), countingCombo(T, Sequence3). countingCombo([], Combination) :- …
FProlog
  • 173
  • 1
  • 1
  • 9
0
votes
2 answers

Prolog - query outputs limited answers

To begin with - this is coursework so I can't post code. This is more about how prolog outputs its answers rather than "is my code right"? I'm creating a predicate that returns all simple paths between a graph, given a list of edges. For example,…
user3186023
0
votes
1 answer

In SWI-Prolog, when calling copy_stream_data, how can I avoid the '|: ' prompt?

I have implemented a cat program in SWI-Prolog by using copy_stream_data. File args.pl: :- module(args, [withFilesOrUserInput/2]). withFilesOrUserInput(StreamFunction, []) :- call(StreamFunction,…
Christian Hujer
  • 17,035
  • 5
  • 40
  • 47
0
votes
2 answers

Variable not printing the entire value Prolog

If I assign something like process([[baby],[boy],[[is]dancing],[with],[[the][family]]],A), then it gives output as A = [[baby],[boy],[[is]dancing],[with],[[..][..]]]. I want it to show all the values on terminal. Something like A =…
0
votes
1 answer

Why do some prolog predicates 'end' automatically, while some require me to press enter/'.' again?

Im using SWI-Prolog and when I try to run some predicates I write, they put a full stop at the end of my answer automatically and go straight to the next line. While some require me to either press enter or put the fullstop there myself. Why is…
Sam
  • 454
  • 4
  • 18
0
votes
0 answers

Prolog doesn't "return" true or false

I got a little problem. I got a Prolog query which "return" the value I want but then as the second value i want it to return true or false. My other queries all work fine but this one doesn't. Thats what i get: queryA(T). T = [..]. thats what I…
Tim
  • 193
  • 4
  • 15
0
votes
1 answer

Why does my replace/2 program always return false?

My goal is to replace the '_' with logic variables in a given list. My code: replace([], []). replace(['_'|As], [_|Bs]) :- replace(As, Bs). replace([A|As], [B|Bs]) :- A \= '_', B = '#', replace(As, Bs). It will return a proper list…
user3928256
  • 903
  • 1
  • 11
  • 17
0
votes
1 answer

Shell commands from the top-level

Apparently, I can use some shell commands from the top-level, ?- pwd. /home/boris true. Others that work are ls, cd. Any idea where those are documented, or what others there are? (This is on Linux, can't check if it also work on Windows).
user1812457
1 2 3
10
11