Code Monkey home page Code Monkey logo

node-prolog-swi's Introduction

node-swipl

A node.js interface to the SWI-Prolog library

For now, this addon supports the creation of rules and facts 'on the fly' and querying.

The SWI-Prolog library requires the SWI_HOME_DIR environment variable to be set (See http://www.swi-prolog.org/FAQ/FindResources.html). Thus an example call could be:

SWI_HOME_DIR=/usr/lib/swi-prolog node tests/a.js

Missing SWI_HOME_DIR will result in

[FATAL ERROR:
    Could not find system resources]

Now builds with node-gyp (Thanks to Johny Jose):

$ node-gyp configure
$ SWI_HOME_DIR=/usr/lib/swi-prolog node-gyp build 

After building, try running:

$ SWI_HOME_DIR=/usr/lib/swi-prolog NODE_PATH=build/Release node tests/a.js

If you like it, use and/or fork it. Corrections and improvements are welcome.

Basic usage

Initialization

var swipl = require('swipl');
swipl.initialise();

Create module

var m = swipl.module("mymod");

Facts and rules (shortcut for m.call_predicate("assert", [ term ]) )

m.assert("likes(romeo, julia).");
{}

Querying - Single solution

m.call_predicate("likes", ["romeo", "X"]);
{ X: 'julia' }

Querying - Query

m.assert("likes(john, julia).");
{}
var q = m.open_query("likes", ["X", "julia"]);
undefined
q.next_solution();
{ X: 'romeo' }
q.next_solution();
{ X: 'john' }
q.next_solution();
false
q.close();
true

Cleanup

swipl.cleanup();

node-prolog-swi's People

Contributors

geremih avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.