13,458 questions
2 votes
1 answer
151 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
83 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
82 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
96 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
112 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
144 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
233 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
108 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
148 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 ...
2 votes
1 answer
171 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 ...
3 votes
0 answers
155 views
Sliding 15-puzzle using CLP(FD)
Below is my code for a shortest-path solver of the well-known sliding 15 puzzle, using CLP(FD). :- use_module(library(clpfd)). % length 35 (starting position plus 34 moves), roughly 11 CPU seconds ...
4 votes
2 answers
126 views
Eliminating three-valued logic predicates choice points with if_/3
I'm trying to completely remove the choice points of my logical or/3 predicate that relates two logical variables and associates it with a third that can be either true or 'u' (unknown) (and when it's ...
0 votes
1 answer
132 views
Prolog, could not derive which predicate may be called
I'm trying to run the program but I get an error: Sandbox restriction! Could not derive which predicate may be called from call(C) expression1(A,B) combined_expression(A,B,C) solve expression1(C, J) :-...
4 votes
4 answers
225 views
How to make this predicate enumerate trees fairly?
We represent the empty tree by the atom 'nil' and the non-empty tree by the term t(X,L,R), where X denotes the root node and L and R denote the left and right subtree, respectively. As such, a ...
1 vote
2 answers
103 views
How do I pass parameters to prolog's Query function?
Here’s an answer to the question: To pass parameters to the Query function in the ichiban/prolog library, you can use Prolog's format/2 syntax for dynamic queries or use compound terms to safely and ...