Prolog is the most commonly used logic programming language. It supports non-deterministic programming through backtracking and pattern matching through unification.

learn more… | top users | synonyms

0
votes
1answer
8 views

How to add elements from sublists with 2 elements (the first element is a string and the second one a number)?

I'm workin on a list that contains sublists with 2 elements each. The first element of each sublist is a string and the second one a number. [ [e, 30], [a, 170], [k, 15], [e, 50] ] I want to add ...
0
votes
1answer
13 views

Best practices for data management in prolog

I'm just getting involved in using Prolog to handle more than just the simplest forms of data (facts) and am looking for some guidance from the seasoned Prologers... If I want to dynamically manage ...
1
vote
2answers
29 views

Create two list from facts

I have these facts: fact(1,'a'). fact(2,'b'). fact(3,'c'). fact(4,'d'). my goal is to create 2 lists: one for the ID and one for the strings. So, something like this one: fact(['a', 'b', 'c' , 'd'], ...
0
votes
1answer
21 views

Error in GNU Prolog

I have this code : :- public queens / 1. :- mode forbidden(+, +, +, +), least_room_to_move(+, -, -, -), lr2m(+, +, +, -, -, -), make_initial_table(+, -), ...
-1
votes
1answer
32 views

Square placing in Prolog

I have a nxn area. And I want to list all of the positions of possible kxk m squares (k < n) which don't touch each other in that area. I want to list the coordinates of the upper-leftmost squares ...
0
votes
1answer
14 views

Building a list in prolog

im a beginner on prolog, and I am trying to return a list of results. Say i have items belonging to a person ie. items(person1,apple). items(person1,orange). I want to be able to create a function ...
1
vote
1answer
47 views

Prolog inserting multiple elements into list

I want to implement a predicate (vecLine2BitLine) which does the following: get two lists and a number the first list is the length of blocks (the elements of the blocks are '$') and the second list ...
1
vote
2answers
45 views

Split lists proplem

I have a proplem in Prolog, I have a list with 81 items and i need to get just 9 items from it in different positions each time, for example if my list is: ...
0
votes
0answers
39 views

DFA parser in Prolog

i have a problem with this code i couldn't understand the error >>> E;Test_Goal, pos: 324, 11 Character constants must be terminated with an apostrophe (') could any one help me please :) domains ...
0
votes
2answers
39 views

How to specify custom order of values in variable's domain?

Let's assume I have a variable V and value of V can be any number from the range 0..5. However, some values are more preferred than other others therefore it would help me to specify the domain of V ...
2
votes
2answers
35 views

Prolog: checking if an unbound set is a subset of a bound set

I have two sets Set1 = [stone(X), active(X), stone(Y), in(app2,Y), unlocked(app2)] Set2 = [stone(s1), active(s1), stone(s2), in(app2,s2), unlocked(app2)] I want my program to recognise that 1 ...
0
votes
1answer
29 views

Combine all of the elements from list of the lists

How can i combine all of the list elements from list in lists? exmaple combine([[a,b,c],[d,[e,f],g],h],X). return X = [a,b,c,d,e,f,g,h] This is what i had try flat([], []). flat([First|Rest], ...
1
vote
1answer
34 views

How work this DCG Prolog grammar that say if a string is a Roman Number?

Searching on StackOverflow I have found this DCG grammar that say inf a string is a roman number and convert it into a decimal number (in this post: Prolog Roman Numerals (Attribute Grammars)): ...
1
vote
2answers
25 views

write elements in a list in prolog

I am learning prolog. How do you write elements in a list in prolog where the list may contains elements beginning with a capital letter. for example: I have the predicate my_write/1 my_write([]). ...
0
votes
0answers
31 views

Parser generator, predicate not returing true or false

I have a some problem with my PROLOG assignment. Namely, I have to write predicate accept(+Automaton, +Word) that return true if Word belong to language (Automaton is represented by Goto table, ...
0
votes
2answers
31 views

Prolog - Getting different results by yielding

I'm trying to write a prolog program which needs to have a predicate that does returns minimum variable every time it called. But i need it in such a way that if you yield the function, it should ...
1
vote
1answer
35 views

Prolog Program to Find Square of Natural Numbers

My code below is meant to generate the square of natural numbers in order (i.e sq(X). -> X=0; X=1; X=4; X=9; X=16; ...) nat(0). nat(X) :- nat(Y), Z is Y+1, X is Z*Z. but the answer I am getting ...
1
vote
1answer
30 views

Clearing Screen in Swipl prolog in windows

When you are running command prompt in windows you can type the clear command to clear the screen. How do you do the same thing when you are running swipl prolog (by typing swipl in the command ...
0
votes
2answers
28 views

gprolog include directive not working

I am running gprolog version 1.4.2 on a Fedora 17 Linux machine. I wrote a small prolog program which runs fine. I defined a few predicates in it that I want to hoist out and use in other prolog ...
1
vote
1answer
22 views

How to concatenate two atoms/strings?

I'm trying to find out how to concatenate two atoms: A = 'my ', B = 'atom', How can I concatenate these two atoms so that the result is: 'my atom' ?
1
vote
1answer
16 views

Tuprolog and defining infix operators

So I have some prolog... cobrakai$more operator.pl be(a,c). :-op(35,xfx,be). +=(a,c). :-op(35,xfx,+=). cobrakai$ Which defines some infix operators. I run it using SWI prolog and get the ...
0
votes
1answer
16 views

How create a single Prolog rule that match with more then a single words list?

I am having some problem to do a particular operation on a specific list. I have a list of tokens where a token represents a word and I want use a single predicate to recognize if some contigous ...
3
votes
1answer
36 views

Any Prolog implementation that allows left recursion?

I wonder if there is any Prolog implementation that allows left recursion in clauses. My intuition is that if the implementation uses a breadth-first goal search, it may support left recursion. But ...
0
votes
1answer
50 views

Correctly building up a list in Prolog

I'm attempting to write a predicate to remove elements from an ordered list in Prolog. This is part of a homework assignment and I'm very confused about how Prolog's semantics work in general. When I ...
1
vote
2answers
25 views

Why does this program 'stop-short' - not trying all permutations?

I am trying to write a simple Noughts-and-Crosses (Tic-tac-Toe) evaluator in Prolog. The first thing I am trying to do is to have the program calculate all possible winning boards. The logic isn't ...
-3
votes
2answers
50 views

Prolog functor replacement within a structure [closed]

Need some ideas to do some functor replacement within a list of structure use a procedure replace(Structure, Results) which takes a list of structures, each of the form cat(a,b,c) with functor cat and ...
0
votes
1answer
36 views

Prolog predicate that do a wrong use of or ;?

I am having some problem to do a specific operation on a specific list. I have a list of tokens where a token represents a word and I want recognize if 5 contigous tokens in this list, reppresents a ...
0
votes
1answer
29 views

how to shift from swiprolog to tuprolog

I got a .pl file through an eclipse plugin called JTransformer.The problem is that the .pl file I got is based on swiprolog and now I need to do query based on prolog in a java file which is easy to ...
1
vote
1answer
40 views

Translate a sentence in prolog

can anyone help me to display untranslated word? for example i want to translate, 'i want to eat', in fact, there is no argument of to...so it will display 'saya mahu to makan'...the word to is remain ...
2
votes
1answer
36 views

Some problems with a Prolog predicate that execute a series of operation on list's elements

I am having some problem to implement a predicate that do some operation on a list. I explain what I have to do with a practical example: The predicate have to work on a list that have the following ...
0
votes
0answers
30 views

Local theft art in prolog program [duplicate]

I have to write program in prolog to solve this logic problem: After a local art theft, six suspects were being interviewed. Below is a summary of their statements. Police know that exactly four of ...
-2
votes
0answers
40 views

Local theft art in prolog [closed]

I have to write program in prolog to solve this logic problem: After a local art theft, six suspects were being interviewed. Below is a summary of their statements. Police know that exactly four of ...
0
votes
1answer
16 views

How read a file and write another file in prolog

I would like to read a file, modify lines and write the results to another file. readtofile :- open('inputfile.txt', read, Str), read_file(Str,Lines), close(Str). read_file(Stream) :- ...
0
votes
2answers
94 views

Prolog Sudoku solver issue

I'm trying to write a sudoku 9 x 9 solver. I have used this following code: :-use_module(library(clpfd)). solve(X, Grid):- X = [A1, A2, A3, A4, A5, A6, A7, A8, A9, B1, B2, B3, B4, B5, B6, B7, ...
-3
votes
0answers
27 views

Prolog database [closed]

I am trying to find which shop sells more than or equal to 4 juices? and Does this juice exist? I have 3 shops: shop 1, 2 and 3. shop(shop1, [lisa,rita,mary], [ juice(a, [orange, berry, ...
2
votes
2answers
28 views

Prolog: slice big list in smaller seperate lists

I'm searching for an opportunity to slice a list into smaller lists, like that: [1,2,3,4] -> [[1,2],[2,3],[3,4]] [1,2] -> [[1,2]] and so on.. First, I searched for an solution with build-in ...
1
vote
1answer
36 views

I can't call a parametric SPARQL query from an internal Prolog predicate

I am going crazy with the following problem: I have a predicate makeQuery/3 that build a parametric SPARQL query to interrogate DBpedia, this one: makeQuery(Place, Query, Row) :- %% e.g. Place = ...
1
vote
1answer
15 views

Prolog. Delete from one index element to another in a list

Please help! I need to delete from one element index to another in a list. So it should look like ?-delm(2,4,[5,6,-3,6,11,56,81],L),write(L),nl. L = [5,11,56,81] So I've done this. ...
0
votes
0answers
18 views

SOLVED - get list of public predicates defined in a module

I know that in Prolog every file defining a module should start with the instruction :- module(module_name, [pred1/arity, ...]). How can I retrieve the list of public predicates exported by a ...
0
votes
1answer
29 views

Prolog how to swap two by two elements in a list function?

I need a function in Prolog: swapcouple(L, L1). swapcouple([a,b,c,d,e], M) --> output M=[b,a,d,c,e] swapcouple([a,b,c,d], M) --> output M=[b,a,d,c]
0
votes
1answer
29 views

What is wrong with the following piece of code in prolog?

I am new to prolog and trying a very simple example on http://www.compileonline.com/execute_prolog_online.php . Here is my code: :- initialization(main). main :- female(ayse). ?- female(ayse). ...
1
vote
0answers
29 views

Creating a SPARQL parameterized query using append/3 predicate

Related to my previous post: How to parameterize a SPARQL query in SWI Prolog? In order to exercise, I was trying to implement a predicate that builds and executes a SPARQL query using only the ...
0
votes
2answers
24 views

checking if sum of list is value in prolog

I'm trying to write a simple predicate that will determine if all the elements of a list add up to a sum, but I don't understand why mine isn't working. It seems like it should work, but when i do ...
0
votes
1answer
19 views

HTML select tag in SWI-Prolog

How can i convert this to SWI-Prolog ? i didn't find on the internet how to write the select in prolog, and can you tell me how can i make the php code work in the ? <select id="data_nastere_zi" ...
0
votes
1answer
46 views

How to define variables for the following scenario in CLPFD?

I have a set of variables T_1, T_2, ..., T_N and I would like to rewrite the following pseudocode in CLPFD: T_1 in 0..59, T_2 in 0..59, ... T_n in 0..59, all_different([T_1, T_2, ..., T_n]), ...
1
vote
1answer
32 views

How to parameterize a SPARQL query in SWI Prolog?

I am having difficulty making the following SPARQL query parametric. First I load the request library: ?- use_module(library(semweb/sparql_client)). % library(uri) compiled into uri 0.02 sec, ...
1
vote
0answers
21 views

Time out using linda server in sisctus prolog

I have this piece of code in a client that connects to a linda server: quest(Ag, Q) :- out(demo(Ag, Q), time_out(in(prova(X,S)), 2000 , R), R==success, write(S). ...
0
votes
1answer
26 views

Prolog: Convert HTML to prolog onClick=window.location

I want to convert my site to prolog and I have this code in HTML: <p align="center"><input type="submit" id="sublog" name="login" value="Log in" /> <input type="submit" ...
-3
votes
0answers
33 views

Prolog: Remove sequences of N odd number in the list [closed]

Example: remove_seq(List, N, NewList). Where N is length of sequence of odd number. ?- remove_seq([2,1,3,5,4,7,3,9,5],3,L). L=[2,4,5]. ?- remove_seq([1,3,2,5,3,5,6,7,3,8],2,L). L=[2,5,8]
0
votes
2answers
58 views

Prolog program won't compute variable answer?

This should be an easy fix, but I can't seem to tackle this, and it's getting frustrating. I've coded a program which computes or verifies that two lists are related because the elements of the second ...

1 2 3 4 5 59