Questions tagged [swi-prolog]

SWI-Prolog is an open source implementation of Prolog that runs on Unix, Windows and Mac.

is an open source implementation of the programming language , commonly used for teaching and semantic web applications. It has a rich set of features and libraries including:

  • Constraint logic programming
  • Multithreading
  • Unit testing
  • GUI
  • Interfacing to Java
  • ODBC and others
  • Literate programming
  • A web server
  • SGML
  • RDF and RDFS

Along with developer tools (including an IDE with a GUI debugger and profiler).

SWI-Prolog runs on Unix, Windows, and Macintosh platforms.

SWI-Prolog has been under continuous development since 1987. Its main author is Jan Wielemaker.

The name SWI is derived from Sociaal-Wetenschappelijke Informatica ("Social Science Informatics"), the former name of the group at the University of Amsterdam, where Wielemaker is employed. The name of this group has changed to HCS (Human-Computer Studies).

http://www.swi-prolog.org/

Useful links

1221 questions
6
votes
2 answers

PROLOG CLPFD How to express this via constraints?

Given the following sample of code: example(Ls) :- Ls = [X,Y], Ls ins 1..2, Cost #= max((X #= 1)*3 + (Y #= 1)*5, (X #= 2)*3 + (Y #= 2)*5), labeling([minimize(Cost)], Ls). The idea is to find the assignment to…
user2460978
  • 735
  • 6
  • 19
6
votes
1 answer

Emacs and Prolog

I downloaded SWI Prolog today but, I am having trouble getting emacs to recognize my prolog files. I am saving my prolog files with the extension .pl however, It keeps thinking they are perl files. In my home directory I have my ./.emacs file and I…
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
6
votes
2 answers

Parsing command line arguments

I'm very confused with prolog, it's way different to any language I've ever used (many languages) How do I go about getting argv[0] from: current_prolog_flag(argv, Argv), write(Argv). Now if I tried to type Argv[0] or Argv(0) or Argv<0> it fails..…
ace007
  • 577
  • 1
  • 10
  • 20
6
votes
1 answer

How to Interfacing SWI Prolog to the Visual Studio 2012

I have a program that interfacing SWI-Prolog in Visual Studio. Previously, I used VS2010 (XP) and everything works fine. Then I upgrade my VS to become VS2012 (Win7) and now I have a problem in my code. When it comes to the following…
Budi Hartanto
  • 337
  • 3
  • 14
6
votes
2 answers

How to include an image in an HTML page served dynamically by Prolog?

If I've bound my Prolog HTTP server to localhost at port 9000, how can I make Prolog generate the right path for my images? For example, if my .pl files and .jpg or .png files are located on the desktop, how do I make the server generate HTML code…
Luka
  • 1,718
  • 3
  • 19
  • 29
6
votes
1 answer

Parsing from standard input

How do I parse the standard input (without buffering)? If I understand correctly, phrase/2 needs a list, and phrase_from_file/2 from library(pure_input) needs a file. I solved my problem using normal predicates (not DCG) and using built-ins like…
user1812457
6
votes
1 answer

What are the optimal green cuts for successor arithmetics sum?

To grok green cuts in Prolog I am trying to add them to the standard definition of sum in successor arithmetics (see predicate plus in What's the SLD tree for this query?). The idea is to "clean up" the output as much as possible by eliminating all…
Pietro Braione
  • 1,123
  • 8
  • 22
6
votes
4 answers

Swi Prolog, unloading source files

Is there a built-in predicate or a easy way to remove from the knowledge database of prolog a source files that has already been consulted? I've gone through the reference manual and didn't find any thing that could do that.
5
votes
4 answers

How can I use the up/down history keys in the SWI-Prolog console?

When I press up/down, I should get - just like unix - the previous commands, but instead I get: Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 6.0.0) Copyright (c) 1990-2011 University of Amsterdam, VU Amsterdam SWI-Prolog comes with…
magus
  • 1,347
  • 7
  • 13
5
votes
2 answers

Linux g++ Embedding Prolog Logic Engine Within C++

I have some logic in a C++ program that is not only insanely complex, it requires multiple solutions for which Prolog is ideal. It's sort of like a firewall config script, checking input for actions, but sometimes more that one action is…
Walt Howard
  • 7,676
  • 1
  • 16
  • 11
5
votes
1 answer

read line to atomic list in prolog

I need to read any line (from user_input) into an atomic list, e.g.: Example line, which contains any ASCII chars. into: [Example,'line,',which,contains,any,ASCII,'chars.'] what I've got so far: read_line_to_codes(user_input,…
nonchip
  • 1,084
  • 1
  • 18
  • 36
5
votes
2 answers

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 |x - n_i| In the below code norm1 computes the…
Tjaden Hess
  • 291
  • 2
  • 11
5
votes
2 answers

Using phrase_from_file to read a file's lines

I've been trying to parse a file containing lines of integers using phrase_from_file with the grammar rules line --> I,line,{integer(I)}. line --> ['\n']. thusly: phrase_from_file(line,'input.txt'). It fails, and I got lost very quickly trying to…
moshewe
  • 127
  • 1
  • 9
5
votes
2 answers

How to set the utf-8 for the code file (.pl) in swi-prolog desktop

I'm trying to develeop for frequently answered questions (faq) about something with using swi-prolog. I use swi-prolog for desktop (AMD64, Multi-threaded, version 8.2.3). The questions and the answers in the faq are written in the native language of…
ilknury
  • 51
  • 4
5
votes
1 answer

How to enable the occurs check in all unifications in SWI-Prolog?

According to Wikipedia: Implementations offering sound unification for all unifications are Qu-Prolog and Strawberry Prolog and (optionally, via a runtime flag): XSB, SWI-Prolog and Tau Prolog. However, when I do apropos(occur) it only finds…
MWB
  • 11,740
  • 6
  • 46
  • 91