Registry / web-framework / tau-prolog

tau-prolog

JSON →
library0.3.4jsnpmunverified

Tau Prolog is an open-source, client-side Prolog interpreter implemented entirely in JavaScript. It aims for high compliance with the ISO Prolog Standard, enabling the development and portability of Prolog applications across various systems. The current stable version is 0.3.4, with releases appearing to be infrequent and focused on bug fixes and minor feature additions. A key differentiator is its compatibility with both web browsers (client-side) and Node.js environments, allowing for seamless integration. It uniquely supports DOM manipulation and event handling using Prolog predicates, and incorporates an asynchronous, callback-based execution model to prevent UI blocking in browsers, which contrasts with many other Prolog systems that operate server-side or via WebAssembly.

npm install tau-prolog
INSTALL
IMPORT
SIG · TAU-PROLOG
T
tau-prolog
web-frameworkjavascriptv0.3.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pl
const pl = require('tau-prolog');
import pl from 'tau-prolog';
For Node.js environments, `pl` is the default module export accessible via CommonJS `require()`. ES module `import` syntax is not officially documented or supported by default for this package.
pl
<script src="tau-prolog.js"></script> // pl is then available globally
When used in a browser environment via a `<script>` tag, `pl` is exposed as a global variable. Ensure `tau-prolog.js` (or a custom bundle) is loaded.
pl.create()
const session = pl.create();
import { create } from 'tau-prolog'; const session = create();
The core functionality, such as creating a new Prolog session, is accessed through methods on the `pl` object. Direct named imports for `create` are not supported.

This code demonstrates how to initialize a Tau Prolog session, consult a Prolog program string, formulate a query, and iterate through all possible answers using the library's callback-based API.

const pl = require('tau-prolog'); const session = pl.create(); session.consult(` likes(sam, salad). likes(dean, pie). likes(sam, apples). likes(dean, whiskey). `, { success: function() { console.log("Program loaded correctly."); session.query("likes(sam, X).", { success: function(goal) { console.log("Goal loaded correctly."); // Look for answers function findAnswer() { session.answer({ success: function(answer) { console.log(session.format_answer(answer)); findAnswer(); // Try to find the next answer }, fail: function() { console.log("No more answers."); }, error: function(err) { console.error("Uncaught exception:", err); }, limit: function() { console.warn("Resolution limit exceeded."); } }); } findAnswer(); }, error: function(err) { console.error("Error parsing goal:", err); } }); }, error: function(err) { console.error("Error parsing program:", err); } });
Debug
Known issues
breakingAs of version 0.3.0, the `consult` and `query` methods on `pl.type.Session` and `pl.type.Thread` prototypes became asynchronous, requiring callback functions for success and error handling. Direct synchronous usage from previous versions will no longer work.
fix
Migrate synchronous `consult` and `query` calls to use the provided callback structure (success, error, fail, limit) as demonstrated in the quickstart example and official documentation.
affects: >=0.3.0
gotchaTau Prolog primarily uses a callback-based asynchronous API, especially for `consult`, `query`, and `answer` methods. This can lead to 'callback hell' in complex scenarios. While it supports asynchronous predicates for non-blocking operations, direct Promises or async/await are not part of the core API for resolution flow.
fix
Structure callbacks carefully, or consider wrapper functions to convert the callback-based API into Promise-based for better readability and maintainability in modern JavaScript codebases. The project mentions that it distributes a package to overcome drawbacks of this interface, but doesn't explicitly name it in the provided context.
affects: >=0.3.0
gotchaWhen comparing Prolog systems, be aware that Tau Prolog aims for ISO Prolog Standard compliance but may have differences in specific built-in predicates or behavior compared to other implementations like SWI-Prolog. For example, `sub_string/5` might not be supported, while `sub_atom/5` is.
fix
Refer to Tau Prolog's specific documentation for supported built-in predicates and module definitions to ensure compatibility and expected behavior. Test your Prolog programs thoroughly within the Tau Prolog environment.
affects: all
gotchaTau Prolog does not support a `trace` predicate for debugging in the same way some other Prolog systems (like SWI-Prolog) do. Debugging complex Prolog execution within Tau Prolog requires alternative strategies.
fix
Instead of a traditional trace, the recommended approach involves systematic removal of goals to identify failing fragments or analyzing program generalizations. Logging output in callbacks can also assist.
affects: all
Errors
Common errors & fixes
Error parsing program
The Prolog program string passed to `session.consult()` contains syntax errors or uses unsupported predicates/constructs.
fix
Review the Prolog program for syntax correctness according to the ISO Prolog Standard and Tau Prolog's specific implementation. Check for missing periods, misplaced commas, or incorrect predicate arity. The error callback for `consult` will provide details.
Error parsing goal
The Prolog goal string passed to `session.query()` contains syntax errors.
fix
Examine the goal string for proper Prolog syntax. Ensure variables are correctly capitalized, predicates exist, and terms are well-formed. The error callback for `query` will provide specific error information.
Uncaught exception
A runtime error occurred during the Prolog inference process (e.g., division by zero, invalid argument type for a predicate, an infinite loop exhausting resources).
fix
Implement robust error handling in the `session.answer()`'s `error` callback to catch and inspect the exception. Debug the Prolog program's logic to identify the source of the exception. For performance-intensive programs, consider using the `limit` option in `session.answer()` to prevent infinite loops from freezing the application.
Resolution limit exceeded
The Prolog interpreter reached the maximum number of resolution steps (default 1000) while trying to find an answer, often indicating an inefficient or infinitely recursive program.
fix
Optimize your Prolog program to reduce the search space or prevent infinite recursion. Alternatively, increase the `limit` option in `session.answer()` if the computation is legitimately long, but be mindful of potential browser blocking.
Upgrade
Version history
0.3.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources
tau-prolog — npm install tau-prolog · libregistry