Did you know ... | Search Documentation: |
Packs (add-ons) for SWI-Prolog |
Title: | A Horn Clause Only library for Prolog |
---|---|
Rating: | Not rated. Create the first rating! |
Latest version: | 0.2.2 |
SHA1 sum: | 6a89e28bd0fc497fabd966e329331df82748c2e2 |
Author: | Neil Hoskins https://buslogic.pro |
Maintainer: | Neil Hoskins https://buslogic.pro |
Packager: | Neil Hoskins https://buslogic.pro |
Home page: | https://github.com/da-poodle/purity |
Download URL: | https://github.com/da-poodle/purity/releases/*.git |
No reviews. Create the first review!.
Version | SHA1 | #Downloads | URL |
---|---|---|---|
0.2.2 | 6a89e28bd0fc497fabd966e329331df82748c2e2 | 1 | https://github.com/da-poodle/purity.git |
0.2.1 | 16953fc3d470109e9786aa6fef7ae4a3719cfd89 | 1 | https://github.com/da-poodle/purity.git |
434f7f808e754b6aabffcc7ec0fdba57aa7f3a7c | 1 | https://github.com/da-poodle/purity.git | |
0.1.3 | 5269b612545c30612804554e7e0eb434280ff82c | 10 | https://github.com/da-poodle/purity.git |
0.1.2 | befff9fba916dccf5fb7d3feefe8d9435f8dadc9 | 1 | https://github.com/da-poodle/purity.git |
0.1.1 | 45b5da96fa18f3b8d71de3133e3d85bf508e9a6e | 1 | https://github.com/da-poodle/purity.git |
0.1.0 | 009edfb0f20ae3f44a39922bf3c9b545582a5c3d | 1 | https://github.com/da-poodle/purity.git |
Purity is a library for Prolog that uses the most basic set of operations possible, which allowing for a rich set of functionality.
Purity is designed to be used as a testing tool for new interpretters and to experiment with 'pure prolog' features.
For more details documentation see the docs folder
The following Prolog features are allowed in Purity:
The modern Prolog language has added a number of new operations on top of these, but they all involve using the cut (!) operator, which is impure.
Purity aims to implement ways to do the same things as Prolog programs that use a cut operator, but by only using the basic Horn clause operations.
To run a program using Purity a normal Prolog interpretter can be used, but a few settings might need to be tweeked. The first is that Purity expects strings as lists of characters, so to make this easier to manager, the following Prolog flag should be set:
:- set_prolog_flag(double_quotes, chars).
Next, because Purity is designed for the simplest compilers, importing library files must be done manually using either consult/1, or ensure_loaded/1 inbuilt predicates. This allows for more simple mechanisms to be used as well.
For example, to load the basic library features for strings the following will work:
:- ensure_loaded(purity). :- ensure_loaded(plist). :- ensure_loaded(pstring).
Because modern Prolog engines have a large set of libraries and features, many of which do not use the kind of `Pure Prolog` that the Purity library does, then it is important to be able to test the library without any advanced features on a modern system, without running and 'impure' functions from the modern system.
Do achieve this, a meta interpretter can be used to wrap queries that are meant to be 'pure'.
% Meta interpretter for 'pure prolog' mi(Goal) :- \+ unclausable(Goal), clause(Goal, Body), mi(Body). mi(true). mi(','(A,B)) :- mi(A), mi(B). unclausable((_,_)). unclausable(true).
Then when running a goal, let's say a goal called find_peeps/1 then run like the following:
mi(find_peeps(X)).
Then only the most basic operations are allowed.
One issue with not using features like cuts in Prolog is that the code can easily become very inefficient, because there is no way to trim unnessecary paths. To get around this Purity exploits two compiler optimisations.
To ensure that choicepoints are not accumulated, ALL clauses should have a unique term as the first argument within a predicate. This is not always easy to do, but the Purity library tries as hard as possible.
There are some limitations of horn clause only code, and I'll give a bit of a list of the things that can't be done (as of this date).
Currently the next step for this project is to create a more effective maths library using strings to represent numbers.
Then some examples will be written.
Pack contains 30 files holding a total of 91.9K bytes.