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

8
votes
1answer
62 views

cat program in Prolog

In order to learn Prolog, I have implemented the cat command in Prolog. I want to know if the code is idiomatic and what could be improved. File ...
0
votes
0answers
18 views

Meta predicate nest/4

Here comes the nest/4 idiom. Hat tip to Wolfram. ...
2
votes
0answers
19 views

meta predicates fixedpoint/3 and fixedpointlist/3

What about the following meta-predicate "fixed point"? ...
4
votes
1answer
31 views

map + foldl = mapfoldl

I was wondering... In the standard library of some Prolog systems, there are meta-predicates like maplist and foldl. In ...
6
votes
0answers
77 views

Higher-order Prolog predicates combine/3 and reduce/3

I'm trying to find useful versatile meta-predicates that are different from the vanilla ones offered currently by library(apply). How about the following two: ...
3
votes
1answer
61 views

SICP Exercise 1.3: Sum of squares of two largest numbers out of three, Prolog Version

The exercise 1.3 of the book Structure and Interpretation of Computer Programs asks the following: Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of ...
2
votes
1answer
47 views

Repeated string concatenation

I've been looking for a way to have a predicate that establishes that all elements of a list are substrings delimited by a given string. Analogues in other languages include: ...
0
votes
0answers
61 views

Simple login system in prolog

The code produces a dialog that allows a user to enter information, then verifies the information and allows the user to have access. Is there any way to improve the code? ...
2
votes
1answer
77 views

Adding elements in two lists as numbers

The problem is adding two lists as numbers L1 = [1,9,9] and L2 = [0,9,9]: ...
5
votes
1answer
67 views

Binary Digits to ASCII Characters

I wrote this code, as a novice a to Prolog, for a challenge posted on /r/DailyProgrammer. The formal description of this challenge, as presented in the prompt reads: Input description On ...
2
votes
1answer
102 views

English phrases, prime numbers, pseudo random data and encryption source code check

This code uses a DCG and pairs phrases into near-English sentences. If anyone is familiar with Prolog, I'm wondering how I can use the code as an encryption method by hiding data and replacing it ...
1
vote
1answer
44 views

Iterating towards a goal

I'm pretty proud of the following, but would welcome any comments from experts: ...
2
votes
1answer
70 views

Implementing an open/close function in Prolog

I'm going through the Adventure in Prolog tutorial and I'm trying to implement an open/close rule for each of the doors I have. Add an open/closed status for each of the doors. Write open and ...
6
votes
1answer
162 views

“Hello world!” in Prolog

I have just written the following "hello world" program in Prolog. Although it is as simple as it can be, I would like your feedback as Prolog is very new to me. ...
5
votes
1answer
56 views

Sample n items without replacement in Prolog

I have the following Prolog code which samples n items from a list without replacement: ...
4
votes
1answer
39 views

Implementing a zipwithindex predicate in prolog

I want to implement a predicate of the form: zipwithindex(?List1, ?List2) which is true when the elements of List2 are the ...
3
votes
2answers
2k views

Prolog Sudoku solver taking too long

I was wondering if there's any way I can improve this code's execution. I want to use it on a 9*9 grid, but it takes too long to solve this as 4*4. This program takes as input a 4*4 matrix ...
4
votes
1answer
341 views

Complete graph traversal algorithm in Prolog

Given a table, I want to explore all possible transition between the elements in the table. ex: for a table with size 3 [0,1,2], the output of the algorithm should be 0->1, 1->0, 0->2, 2->1, 1->2, ...
0
votes
2answers
924 views

Range of all variables in List in Prolog

I have a list in Prolog like this: Puzzle = [ A1, A2, A3, B1, B2, B3, C1, C2, C3 ]. And I want every variable in the list to be a number ...
1
vote
1answer
253 views

Bibtex reader using Prolog

I am trying to learn Prolog, and wrote a bibtex reader using GNU Prolog. I would like some feedback on my code in terms of: the way I write Prolog, and how it can be improved. Gist ...