Questions tagged [swi-prolog]
SWI-Prolog is an open source implementation of Prolog that runs on Unix, Windows and Mac.
1,139
questions
0
votes
1
answer
12
views
SWI-Prolog: Looking for a way to print dictionary values in seperate lines
I am searching a way to print some dictionary values in a way every value is on a separate line in the terminal.
For example if I have
X = abc{a:1,b:2,c:3,d:4,e:5,f:6,g:7,h:8,i:9,j:10}.
The output ...
0
votes
0
answers
23
views
No theory in Aleph SWI Prolog
My question is pretty similar to Not getting a theory in Aleph for SWI Prolog
After trying to induce a theory, I end up getting only single atoms
My code(only a snippet of examples included for ...
0
votes
0
answers
20
views
How i can open more than one form in prolog ,i used MDI
I used this code when I clicked in button in first form:
predicates
onPushButtonClick:button::clickResbonder.
clauses
onPushButtonClick(_Source)=button::default Action:-
_=second_form::display(This).
0
votes
0
answers
30
views
Variables from Java to Prolog
i am new here and have searched far and wide for this so please help me.
I have a game in SWI-prolog which is basically an army of 8 white pawns vs 8 black pawns that fill a board of 16 positions to ...
0
votes
1
answer
35
views
SWI-Prolog library `assoc:get_assoc` won't unify
I'm using library assoc from SWI-Prolog. Here's a query which confuses me:
?- empty_assoc(E), put_assoc(K, E, V, E2), get_assoc(key, E2, 2).
false.
Why doesn't this unify?
I'd expect it to unify with
...
1
vote
2
answers
60
views
Incrementing value on backtrack
how can I do increment on backtracking ... so that goal(S) receives incremented number .. every time it fails on the next run I want to get the next number
S1 is S + 1,goal(S1)
does not work, because ...
-1
votes
1
answer
31
views
How to install / use Prolog on Mac Monterey
I have xQuartz installed as I use VSCode to code with c++. I am a bloody beginner and have absolutely no clue how to use SWI Prolog with the built in editor on my Mac. Or VSCode as an editor.
None of ...
1
vote
1
answer
37
views
Extending and/or parametric object as attribute
As I understand now from Array as object I have to use parametric object, because using non-parametric Logtalk objects implies that I have to use assert i.e. any change/set rewrites the whole array.
...
2
votes
1
answer
41
views
Prolog: How to switch negative indexes of dictionary into positive successors of the maximal index?
I have some SWI-Prolog dictionary of following form:
dict_label{-N: a(-N), -N+1: a(-N+1), ..., -1: a(-1), 1: a(1), ..., M: a(M)}.
whereby:
a(j), -N≤j≤M are the values of the dictionary with keys in ...
2
votes
1
answer
51
views
Objectifying Array based on Term
I have this for array :
ary1d_new(Size,Sym,ArySym,Ary) :-
functor(Ary,ArySym,Size),
forall(arg(X,Ary,_), nb_setarg(X,Ary,Sym)).
ary1d_get(Pos,Ary,Val) :- arg(Pos,Ary,Val).
ary1d_set(Pos,Ary,...
0
votes
0
answers
31
views
Reading lists dynamically in prolog
I am fairly new to Prolog and need help with the following.
There are two lists: list_A and list_B, where list_A is a shorter list than list_B. For each item in list_A I want to check whether it is ...
0
votes
1
answer
60
views
Prolog: Cast term into string?
I have a Prolog program, which generates terms of this form:
:-op(803, xfy, →).
connect(X, Y, Result):-
Result = (X → Y).
if I now call connect(a,b,R) my result is R = (a→b). Is their a ...
0
votes
0
answers
30
views
How i can connect Prolog and PyQT5
I write a program on prolog with graphick interface PyQT5. I call the prolog file from python file, but i dont know, how i can send prolog questions in Python variable. I need it because i want show ...
2
votes
2
answers
60
views
Incrementing datetime by second
I'm trying to take a datestring, e.g. 2020-03-04 06:22:59.012315131 and increment it by one second so it becomes 2020-03-04 06:23:00. The ms ending part doesn't matter.
Using the date library I have ...
0
votes
0
answers
53
views
How to add a time limit to find object in prolog game?
I am coding an adventure game in swi-prolog and I am fairly new to it, but I understand the basics. I am trying to figure out how to set a time limit to give the user around 5 minutes to find objects ...
0
votes
1
answer
33
views
Filter tuple facts to new list
I'm having an issue with trying to filter facts imported through a CSV. I have the following CSV file:
"colA","colB","colC","colD"
"what","is&...
0
votes
1
answer
126
views
Send list from Python to Prolog PySwip
I`m writing a program on Python and Prolog, using the library PySwip. I need to send list from Python to Prolog. i did it like this:
from pyswip import Prolog
p = Prolog()
p.assertz("fruits([...
0
votes
0
answers
32
views
What's the default SWI-Prolog font?
So,
I accidentally changed font on the SWI-Prolog listener and I can't find the default one.
What's the default font name?
0
votes
0
answers
53
views
Package installation from git in SWI prolog
I am attempting to install library(reif) on Ubuntu 20.04 from git using the pack_install/1 predicate of SWI prolog. Here is the output.
% Contacting server at https://www.swi-prolog.org/pack/query ... ...
0
votes
1
answer
76
views
Forward chaining in prolog with rules about lists
In previous question, we built a simple forward chaining in Prolog together with the user slago, and solved some problems about it.
Code for forward chaining:
:- op(1100, xfx, if).
:- op(1000, xfy, or)...
1
vote
0
answers
61
views
SWI-Prolog stand alone executable
I am trying to create an windows SWI-Prolog executable. I have created the desired executable using this command line argument.
--goal=main --stand_alone=true -o myprog -c file.pl
but when I try and ...
2
votes
1
answer
77
views
Forward chaining in Prolog, problem with multiple rules
in my previous question's best answer, I found a good example of forward chaining in Prolog. I have modified it a bit, but there is a problem with the last rule I tried to define (path). It doesn't ...
3
votes
2
answers
121
views
Can the unification algorithm in Prolog recurse infinitely?
I am using swi-prolog to produce some examples for students in the context of a Prolog course. Regarding unification I want to draw their attention to the dangers of infinite recursion in the ...
1
vote
1
answer
55
views
Python: convert dictionary from swiplserver
I am using swiplserver for using prolog queries in python. Within that queries I get dictionaries of this kind:
to_translate = {'A': 'p', 'B': '_', 'C': 'q', 'Z': {'→E': {'args': [['p', {'args': ['p', ...
0
votes
0
answers
38
views
SWIPL PROLOG as JSON Query
I have a knowledge base represented as PROLOG facts.
I run swipl commands in a pipeline, each step emitting a new set of facts.
I append the new facts to the old knowledge base using bash commands.
...
0
votes
1
answer
49
views
Why is my prolog program stucked in endless recursion
I have the following experimental code
s(a,b).
s(b,c).
s(c,b).
r(a).
r(c).
r(d).
p(X,Y) :- s(X,Y), not(r(Y)).
q(X,Y) :- q(Y,X), r(X).
q(X,Y) :- p(Y,X), s(X,Y).
t(X,Y) :- r(X), q(X,Y).
Querying for t(...
0
votes
0
answers
52
views
Can't install Prolog
I'm trying to download SWI-Prolog, but I keep having this error, do you know what i am supposed to do?
$ sudo apt install swi-prolog-nox
Reading package lists... Done
Building dependency ...
1
vote
1
answer
38
views
How to delete entry from rdf file in prolog
I want to write a program in Prolog where a menu is given to the users. They choose to either add data, see existing data based on surname or age, or/and delete data based on surname or age. I don't ...
0
votes
0
answers
40
views
phrase_from_file and lazy_input
I'm trying to use a simple DCG to read from a file and give me a match plus the remainder. In other words, I want to get (and eventually handle) the rest of the input that did not match the list ...
0
votes
1
answer
53
views
How can I fix sandbox error on SWI-Prolog
I'm trying this code on SWI-Prolog:
go :-
write('What is the patient''s name? '),
read(Patient),
hypothesis(Patient,Disease),
write_list([Patient,'probably has ',Disease,'.']),nl.
go :...
1
vote
0
answers
42
views
How using upcase_atom/2 in Prolog?
Here is a minimal theorem prover in Prolog:
:- op(1110, xfy, =>). % conditional
% -----------------------------------------------------------------
provable(F,P):-
prove([]>[F],P).
% --...
0
votes
2
answers
100
views
Python: swiplserver load prolog file
Based on this post try to follow the hint with setup some swiplserver
from pyswip import Prolog, Functor, Query
from swiplserver import PrologMQI, PrologThread
prolog = Prolog()
prolog.consult("...
2
votes
1
answer
63
views
How to you list Prolog queries and then print each query and its result(s) programmatically?
I have the following file named movies.pl:
acted_in('Brad Pitt', 'Babel').
acted_in('Cate Blanchett', 'Babel').
acted_in('Sharlto Copley', 'District 9').
acted_in('Sharlto Copley', 'Elysium').
...
2
votes
1
answer
46
views
SWI Prolog: avoiding name clashes between builtin predicates and dynamic predicates
I'm wondering if it is possible to define a dynamic predicate with the same name and arity as a builtin predicate inside a module. I was hoping it would be enough to hide the builtin predicates in my ...
3
votes
1
answer
63
views
Prolog findall solutions within time limit
I would like to find all solutions to a goal within some time limit. I mean that I would like to search for solutions for at most the time limit, and return all solutions found, whether the time limit ...
1
vote
1
answer
60
views
How can I improve error reporting using PlUnit?
I'm writing tests using SWI-Prolog's PlUnit and would like to provide a better error message, perhaps by diffing what I've got from what I was expecting.
The following minimal working example (MWE) ...
0
votes
0
answers
38
views
Running Prolog in Eclipse (Mac)
I am currently trying to set up Prolog in Eclipse on Mac. I have installed ProDT via the Eclipse marketplace, however, when I try to open or create a Prolog project, I receive the error that there is ...
5
votes
2
answers
154
views
Why is this CLP(FD) constraint solving slowly and how do I debug it?
I'm learning Prolog by doing the Advent of Code challenges.
Spoilers for Advent of Code 2021 day 7 below:
The objective is: given a list of natural numbers n_1,..., n_k, find
min_(x\in \N) \sum_i=0^k |...
1
vote
1
answer
58
views
Use expand_term/2 with file for dcg translation
I'm trying to "translate" a file that contains dcg's. in particular i am trying to transform all dcg into normal definite clauses using expand_term/2, however i would like to avoid manually ...
2
votes
0
answers
123
views
Tool for drawing SLD trees in Prolog
Just as an example, I have the following SWI-Prolog Program (inverts a list):
inverte(L,LI) :-
inverte(L,[],LI).
inverte([], Aux, Aux).
inverte([P | R], Aux, LI) :-
inverte(R, [P | Aux], LI).
...
0
votes
1
answer
44
views
Using prolog without the pl file
My python application works well and uses swi_prolog's consult, asserts, and query functions along with a pl file. However, when I call the code via web (I get access error at consult when trying to ...
1
vote
2
answers
107
views
Checking IP like address list with Prolog
I'm trying to build a predicate that given a list (eg. ['1', '2', '3', '.', ... , '2']) it has to recognise it as an IP string in the format (NNN.NNN.NNN.NNN) where N is a digit (between 0 and 9) it ...
1
vote
2
answers
180
views
Graph representations in Prolog
Consider the following graph
and that it is described by the below Prolog term :
graph([connected(a,[b,c]), connected(b,[a,c]), connected(c,[a,b,d]), connected(d,[c]) ]).
I would like to define a ...
1
vote
1
answer
154
views
Check if list is made up by numbers only - Prolog
I need to write a predicate that returns true if a given list contains only numbers in Prolog. Example:
?- isDigit(['1', '2', '3']).
true
This is the code I've made so far:
isDigit(X) :- digit(X).
...
1
vote
1
answer
53
views
How does declaring variables in swi prolog work?
Sorry for the inconvenience, I'm still new to Prolog's syntax, Im just asking how would one declare/instantiate and manipulate a variable X (if possible) and be able to write/print it out similar to ...
0
votes
1
answer
49
views
Showing Swi-prolog backtrace?
I figure it may not be built to do that but I might ask.
I want to run a simple cli application and have it show the backtrace in case of error.
swipl -f test.pl -g test(X)
This runs the goal test in ...
0
votes
1
answer
49
views
How can I print the contents of a list stored in database, one by one?
I am trying to learn Prolog on my own and wanted to figure out how to print the contents of a list stored in a database, one by one.
My thought is that if I open (consult) this in SWI-Prolog, I can ...
1
vote
2
answers
66
views
Constraint Handling Rules in SWI Prolog: The `neq` constraint doesn't work
I am learning Constraint Handling Rules (CHR) in swi-prolog.
I started with the tutorial from Tom Schrijvers' Constraint Handling Rules A Tutorial for (Prolog) Programmers.
In p.286, the author gave ...
1
vote
1
answer
69
views
Constraint Handling Rules in SWI Prolog: What's the order of puting a constraint to the store?
I am learning Constraint Handling Rules (CHR) in swi-prolog.
I started with the tutorial from Tom Schrijvers' Constraint Handling RulesA Tutorial for (Prolog) Programmers.
The confusion part is that ...
1
vote
1
answer
28
views
Prolog Can't get to the predicate
The prolog is supposed to find the order of five statements statements. Everything is working fine but when i call the query solution([A, B, C, D, E]) I get a sandbox error like this:
The Error:
...