gprolog | GNU Prolog is a native Prolog compiler | Translation library
kandi X-RAY | gprolog Summary
kandi X-RAY | gprolog Summary
GNU Prolog
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of gprolog
gprolog Key Features
gprolog Examples and Code Snippets
Community Discussions
Trending Discussions on gprolog
QUESTION
I'm trying to migrate my SWI Prolog application into the GNU Prolog. Unfortunately I have a problem with unit tests. In SWIPL we can simply use plunit module and write the test cases like the following one:
...ANSWER
Answered 2021-Jan-30 at 01:43QUESTION
I am trying to write an implementation of Dijkstra's Algorithm in Prolog (specifically, GNU Prolog). To begin, I made a fact connection
that describes the connected vertices of the graph below.
It now seems like my implementation works for around half of my test cases, namely these:
...ANSWER
Answered 2021-Jan-17 at 08:26The main idea of dijkstras algorithm is to create a boundary between visited and unvisited nodes. Everything happens in the boundary. The boundary are simply pairs of nodes and their distances from the start node. In each step the node from the unvistied set with the smallest total distance from the start is transfered to the vistied set. To do this all "connections" from any visited nodes to unvisited nodes are checked: distance to the vistited node + connection value is the total distance. This way you can get the minimal distance from start to goal. Please note that this (mostly deterministic) algorithm works with those two sets rather than a concrete path. However if you want to have a path you have to keep track of the source node for each node in the visited set as well.
Your code seems to have multiple issues and I found it way easier just to implement my own solution. One of the problems is that the start node appears in the unvistied list. You can use the following code as a reference to debug your code:
QUESTION
I have been reading the GNU Prolog documentation to figure out how to read a line of input until an end_of_file
atom is reached. Here is my pseudocode for writing such a goal:
ANSWER
Answered 2020-Dec-22 at 04:11You are using peek_char/1
to get the next character, but that predicate does not consume the character from the stream (it just "peeks" the stream). Therefore an infinite recursion undergoes in your code that ends with a global stack overflow.
You should use get_char/1
to read and consume the character from the stream, and reverse/2
the list of collected chars:
QUESTION
To learn some Prolog (I'm using GNU Prolog) and grok its parsing abilities, I am starting by writing a Lisp (or S-expression, if I'm being exact) tokenizer, which given a set of tokens like ['(', 'f', 'o', 'o', ')']
should produce ['(', 'foo', ')']
. It's not working as expected, which is why I'm here! I thought my thought process shined through in my pseudocode:
ANSWER
Answered 2020-Dec-17 at 08:59How about this. I think that's what you want to do, but let's use Definite Clause Grammars (which are just horn clauses with :-
replaced by -->
and two elided arguments holding the input character list and remaining character list. An example DCG rule:
QUESTION
I'm trying to create a function in GProlog that I think is rather simple but I'm having issues writing it.
The idea is to assume a weighted directed graph is described by means of a predicate edge/3, such that edge(X,Y,C) is true is there is an edge from vertex X to vertex Y of cost C. For instance, to the right is a graph and its description using edge/3: edge(a, c,1). edge(a,d,3). edge(b,d,2). edge(c,e,5). edge(e, c,2). edge(e,f,2). edge(d,f,10).
The objective is to define a predicate cheaperPath/3, such that cheaperPath(X,Y,N) is true if there is a path from X to Y of total cost less than N. The predicate is supposed to be called with X, Y and N all instantiated, for example to the query cheaperPath(a,f,7) the anwer should be no.
Here is what I have done for now in Gprolog but the loop seems to be going on and on:
...ANSWER
Answered 2020-Dec-01 at 19:58You should reduce the bound when you take an edge, so:
QUESTION
On the one hand:
...ANSWER
Answered 2020-Nov-07 at 22:53Just an artifact of the SICStus Prolog top-level. Try e.g.
QUESTION
EDIT : I've just compiled gprolog
from sources.
It works fine. The version 1.4.5 in the Debian repo is bugged.
It's my first program in GNU Prolog (gprolog) without any success. :-(
I found these exercises in a Prolog tutorial.
...ANSWER
Answered 2020-Sep-23 at 13:38It seems that invoked with a file name, gprolog
validates it but does not load its content into the interpreter. In order to load the file content you have to use the --consult-file
command line option:
QUESTION
The following sample program generates a schedule while matching certain conditions.
Conditions:
- assigns one employee per shift
- no employee should work consecutive shifts
- do not assign employee for personal holidays
The program provides valid solutions, but takes about 4 minutes although there should be only 128 possible combinations (combine 2 employees on 7 shifts). The program was executed using gprolog implementation within a single core virtual machine.
How is this possible? What is happening?
...ANSWER
Answered 2020-Jun-15 at 16:24takes about 4 minutes although there should be only 128 possible combinations (combine 2 employees on 7 shifts)
It's true that this should be the search space, but you explore a lot more. Consider the first two answers from your predicate:
QUESTION
I'm trying to make a sublist out of a list of lists in gprolog. Say I have a list like this:
...ANSWER
Answered 2019-Dec-09 at 12:48I have attached my approach below. Iterate through the list until it's empty. If 'q' is present in the head then add that to a list. If not present do nothing keep iterating.
QUESTION
My program runs fine on swi prolog but when i try run it using gnu-prolog. It does not run successfully. Im getting this error which I have no idea how to fix.
This is my first error
gprolog [myprojectname]
...ANSWER
Answered 2019-Nov-07 at 03:35The writeln/1
predicate is not a standard predicate and is not supported in GNU Prolog. Replace it with a combination of the standard predicates write/1
and nl/0
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install gprolog
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page