13,459 questions
Best practices
2
votes
2
replies
78
views
What is the best way of building a database piece by piece in prolog?
I have a (SWI-)Prolog program that is organized in the following way :
It revolves around a core module that expose a function, let us call it query/2, that takes a query (a certain data structure, ...
0
votes
0
answers
65
views
How do I have a generate multiple answers from a query when using recursion?
I am trying to process a list of terms and generate a list of alternative terms from that list. I am recursing through the list and trying to generate the new term but also match against the existing ...
1
vote
1
answer
69
views
How do I define and query a mirrored/asymmetric relationship in Prolog?
I am trying to use Prolog to query a simple relationship of "left" and "right" and the asymmetric relationship of left and right.
Your left is my right and my right is your left
I ...
2
votes
2
answers
179
views
How does prolog know when to end recursion when using DCGs to reverse a string?
I am using scryer prolog. I got this from Power of Prolog youtube channel:
qes([]) --> [].
qes([L|Ls]) --> qes(Ls), [L].
Using listing I got it's form in prolog clauses:
?- listing(qes/3).
qes([...
1
vote
1
answer
45
views
Prolog: Simple rule to get difference between numbers fails and does not retry
I am following Sterling and Shapiro's "The Art of Prolog" and I came across exercise 2.3.i:
Add rules defining the relations location(Course,Building),
busy (Lecturer,Time), and cannot-meet ...
3
votes
2
answers
227
views
How to prevent DCG from finding extra results?
I am writing a small DCG to parse a grid of numbers. I have set it up to parse them into a list of lines, with each line being a list of numbers. I am using the library(dcg/basic) from swi-prolog to ...
1
vote
1
answer
102
views
Prolog cut not preventing the backtracking I expected it to - what's wrong with this code?
Writing a small set of date math predicates using scryer prolog, evaluating in emacs using edi-prolog. There's a cut in the first branch of date_end_of_month below, which I intended to mean "If ...
1
vote
1
answer
107
views
In scryer prolog, how do I provide stdin to `phrase_from_stream`?
It seems that the correct way to read user input in prolog is to use phrase_from_stream, providing stdin as the stream. How in Scryer Prolog does one bind a variable to the stdin stream in order to do ...
2
votes
1
answer
104
views
How is call/3 working with a principal functor and one argument?
In this example from the reif module, C_2 takes two arguments. So what is happening here when C_2 is called with one argument?
tfilter(_, [], []).
tfilter(C_2, [E|Es], Fs0) :-
if_(call(C_2, E), Fs0 ...
3
votes
1
answer
129
views
How do I make a Prolog rule that only reads the lists inside lists?
I am somewhat new to Prolog, having only practised for a few months so far. I am stumped on the following problem and nothing I googled seemed to help.
I wrote the following code into a Prolog ...
1
vote
1
answer
184
views
How to avoid infinite loop with recursion
I'm having trouble with a personal Prolog exercise. For context, the idea is to make a little digital logic tool which makes cell instances and pin connections. The hope is to let the program manage ...
2
votes
1
answer
246
views
How to represent a labyrinth state space in SWI-Prolog?
I'm trying to represent the state space of a labyrinth using SWI-Prolog. The labyrinth consists of labeled rooms connected by bidirectional paths. Room 'a' is the entry point (initial state), marked ...
1
vote
1
answer
133
views
How do I represent and manipulate atoms with capital letters in Prolog, without them being interpreted as variables?
I'm developing a program in Prolog that interprets a chessboard notation. The input is a forsyth notation as a list containing pieces represented by letters, as in the example: [[t,c,b,r,d,r,b,c,t],8,...
2
votes
3
answers
159
views
Cut operator not discarding choice points?
Disclaimer: Yes, this is for an assignment, but I think I have an alternative solution already. I just want to figure out why this initial attempt did not work because I can't understand why it isn't ...
3
votes
1
answer
189
views
How is one meant to parse the phrase "pure monotonic Prolog"?
The phrase "pure monotonic Prolog" (sometimes written with a comma) is often used in discussion of the language, especially in discussion of how one ought to write code. How is the phrase ...