Questions tagged [prolog]

Prolog is the most commonly used logic programming language. It supports non-deterministic programming through chronological backtracking and pattern matching through unification. Do not use this tag like Prologue and Epilogue.

Prolog is the oldest and most popular logic programming language. Its built-in features include non-deterministic programming through backtracking and a powerful parser formalism called Definite Clause Grammars (DCG) . Modern variants often support some form of constraint programming. It is used for automated reasoning, deductive databases, planning and scheduling tasks, natural language processing, engines for web/business rules and is often used to introduce the declarative paradigm in school.

There is an ISO/IEC standard for Prolog .

Further efforts in harmonizing implementations can be found at Prolog Commons.

Prolog-related tags

Core language:

Modules:

Environment:

Arithmetics:

Puzzles:

Problems:

Implementations:

  1. SWI (free)
  2. SICStus (commercial)
  3. GNU (free)
  4. XSB (free)
  5. B (commercial, discontinued, now Picat)
  6. IF (commercial)
  7. Ciao (free)
  8. Minerva (commercial)
  9. ECLiPSe-CLP (free)
  10. Prolog IV (free)
  11. Tau (free)
  12. Scryer (free)
  13. C-Prolog
  14. trealla

free = allows commercial use without royality

Forums

Free Prolog Programming Books

Languages influenced by Prolog

Microsoft Guan

Historical Archive

Prolog and Logic Programming Historical Sources Archive

Useful links

13358 questions
4
votes
1 answer

How to check if the value is a number in Prolog manually?

How to check if the given value is a number in Prolog without using built-in predicates like number? Let's say I have a list [a, 1, 2, 3]. I need a way to check if every element within this list is a number. The only part of the problem that bothers…
Luka
  • 1,718
  • 3
  • 19
  • 29
4
votes
3 answers

Parser Implementation

Hi I am trying to implement a parser for a simple language with grammar like this. program ::= "program" declarations "begin" statements "end" declaration ::= "var" ident "as" type type ::= "string" | "int" I have the first two done, how would I…
4
votes
3 answers

What's the SLD tree for this query?

Let's consider the following Prolog program (from "The Art of Prolog"): natural_number(0). natural_number(s(X)) :- natural_number(X). plus(X, 0, X) :- natural_number(X). plus(X, s(Y), s(Z)) :- plus(X, Y, Z). and the query: ?- plus(s(s(s(0))),…
Pietro Braione
  • 1,123
  • 8
  • 22
4
votes
3 answers

Is There a Way to Consolidate Facts?

Is there a way to turn this: genre(blues). gere(hiphop). genre(rock). Into something like this: genre(blues;hiphop;rock). *I know this does not work, but does something similar to this exist.
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
4
votes
4 answers

Connect between java and swi prolog

I am trying to run swi prolog from java. I am using eclipse and I have inserted jpl.jar into the project (properties->libraries->add external jar) and when I try to run a program (it is a sample of jpl so it should work..) I get an error: Exception…
Noray
  • 165
  • 2
  • 6
4
votes
3 answers

Splitting a list in prolog

I'm pretty new to Prolog, and I need some help with a small problem: I'm trying to split a list of couples in two lists. The first list contains all the couples with the given key, the second list contains all the other objects. This is the code I…
Walle
  • 540
  • 1
  • 9
  • 32
4
votes
1 answer

Prolog Recursion returns multiple results

To start off this is a homework question poised to me. I am supposed to write a predicate btree_height\2 that takes a Binary tree and (for now) just returns the height of the tree. A binary tree is represented as: node(node(leaf, x, leaf), x,…
OmegaTwig
  • 243
  • 1
  • 4
  • 15
4
votes
3 answers

Prolog compute the permutation

I'm writing a permutation function [a,b]-->[[[a], [b]], [[a, b]] I have this so far, but it doesn't work. perm([],[]). perm(L,[H|T]) :- append(V,[H|U],L), append(V,U,W), perm(W,T).
John
  • 827
  • 5
  • 15
  • 25
4
votes
1 answer

Prolog insertion sort

There is a simple Prolog insertion sort alghoritm: sorting([A|B], Sorted) :- sorting(B, SortedTail), insert(A, SortedTail, Sorted). sorting([], []). insert(A, [B|C], [B|D]) :- A @> B, !, insert(A, C, D). insert(A, C, [A|C]). It does well on normal…
Olga Dalton
  • 829
  • 3
  • 15
  • 25
4
votes
1 answer

Building Shared Libraries Using Languages other than C/C++ in particular prolog

Is it possible to build shared libraries (e.g. *.so, *.dll) using languages other than C or C++? What is the underlying requirement to build a shared library? Is it that the language be capable of compiling to a native binary? I'm particularly…
bph
  • 10,728
  • 15
  • 60
  • 135
4
votes
3 answers

counting the number of a particular element in a prolog list

I am trying to count how many times a element appears in a list, so far I have came up with rate(X,[H|T],N):- X == H, N is N+1, rate(X,T,N). rate(X,[_|T],N) :- rate(X,T,N). rate(_,[],N) :- N is 0. I've covered when the a match is found,…
rex
  • 319
  • 2
  • 4
  • 10
4
votes
1 answer

Cryptarithmetic puzzle (Prolog)

I was asked to write a Prolog code to solve the cryptarithmetic puzzle, using "generate and test". For example I get solve([R,O,B],[B,E,R,T],[N,O,R,E,S]) and I need to find an assign for the letters. So I wrote this code: sum(List1,List2,SumList)…
Ygandelsman
  • 453
  • 7
  • 16
4
votes
5 answers

Why my predicate in Prolog Fib/2 always says "out of local stack"?

I wrote a predicate fib/2 to calculate the Fibonacci numbers in Prolog. Though it works, it always says "out of local stack" and the error looks like: ?- fib(10, F). F = 55 ; ERROR: Out of local stack my predicate is below: fib(0, 0). fib(1,…
zzx
  • 179
  • 2
  • 12
4
votes
2 answers

prolog trace how to use

How to go second step when trace prolog program? For example, I want to trace following simple program: length1([],0). length1([_X|Xs],N):- length1(Xs,N1), N is N1+1. I trace program: ?- trace,length([1,2,3],N). Call: (7) length([1, 2, 3],…
Ali Ismayilov
  • 1,707
  • 3
  • 22
  • 37
4
votes
3 answers

Flatting a list

I need to write a function that flat a list. For example: flat([ c , [[[]]] , [] , k] , X). X=[c,k] this is what I did: flat([],[]). flat([[A] |B] , R) :- flat([A|B],R). flat([[]|L],L1) :- flat(L,L1).! flat([[A|L]|W],R) :-…
user1479376
  • 327
  • 1
  • 2
  • 10
1 2 3
99
100