项目作者: luciangreen

项目描述 :
Converts Prolog algorithms to List Prolog algorithms
高级语言: Prolog
项目地址: git://github.com/luciangreen/Prolog-to-List-Prolog.git
创建时间: 2019-06-02T05:21:56Z
项目社区:https://github.com/luciangreen/Prolog-to-List-Prolog

开源协议:BSD 3-Clause "New" or "Revised" License

下载


Prolog-to-List-Prolog

Converts Prolog algorithms to List Prolog algorithms

Prerequisites

  • Use a search engine to find the Homebrew (or other) Terminal install command for your platform and install it, and search for the Terminal command to install swipl using Homebrew and install it or download and install SWI-Prolog for your machine at SWI-Prolog.

Mac, Linux and Windows (with Linux commands installed): Prepare to run swipl

  • In Terminal settings (Mac), make Bash the default shell:
  1. /bin/bash
  • In Terminal, edit the text file ~/.bashrc using the text editor Nano:
  1. nano ~/.bashrc
  • Add the following to the file ~/.bashrc:
  1. export PATH="$PATH:/opt/homebrew/bin/"
  • Link to swipl in Terminal:
  1. sudo ln -s /opt/homebrew/bin/swipl /usr/local/bin/swipl

1. Install manually

Download this repository and the List Prolog interpreter.

2. Or Install from List Prolog Package Manager (LPPM)

  1. mkdir GitHub
  2. cd GitHub/
  3. git clone https://github.com/luciangreen/List-Prolog-Package-Manager.git
  4. cd List-Prolog-Package-Manager
  5. swipl
  6. ['lppm'].
  7. lppm_install("luciangreen","Prolog-to-List-Prolog").
  8. ../
  9. halt.

Running Prolog to List Prolog

  • In Shell:
    cd Prolog-to-List-Prolog
    swipl
    ['p2lpconverter.pl'].

Run:

Convert Prolog code to List Prolog code by copying Prolog algorithm into test1.pl and running: p2lpconverter(S1),pp0(S1,S2),writeln(S2).

Tests

Prolog to Simple List Prolog

Install:
Load each file into SWI-Prolog using ['la_strings.pl']. and ['p2slpconverter.pl'].

Run:

Convert Prolog code to List Prolog code by copying Prolog algorithm into test1.pl and running: p2slpconverter.
Input:

  1. a.
  2. b(C,D).
  3. ef(G):-(h(I)->true;true),!.

Note: [a,*,*] not a, which is Simple List Prolog. [a,*,*] is for inputting into CAWPS predicate dictionary.

Output:

  1. [[[a,*,*]],[[b,*,*],[c,d]],[[ef,*,*],[g],:-,[[[[h,*,*],[i]],->,true,or,true],!]]]

Pretty-print List Prolog algorithm by typing e.g.:

  1. pp0([[[a,*,*]],[[b,*,*],[c,d]],[[ef,*,*],[g],(:-),[[[[h,*,*],[i]],->,true,or,true],!]]]).`
  2. Output:
  3. [
  4. [[a,*,*]],
  5. [[b,*,*],[c,d]],
  6. [[ef,*,*],[g],(:-),
  7. [
  8. [[[h,*,*],[i]],->,true,or,true],
  9. !
  10. ]]
  11. ]
  • See also State Machine to List Prolog, which converts from the State Machine generated within SSI (a Prolog compiler written in Prolog) to List Prolog (a version of Prolog with algorithms written as lists). The State Machine may be operated on by, for example, optimisers.