| Crates.io | neorusticus |
| lib.rs | neorusticus |
| version | 0.1.3 |
| created_at | 2025-08-07 18:39:07.878535+00 |
| updated_at | 2025-10-05 10:34:17.146131+00 |
| description | A Prolog implementation in Rust with enhanced error handling |
| homepage | |
| repository | https://github.com/fermatrox/neorusticus |
| max_upload_size | |
| id | 1785648 |
| size | 1,762,894 |

A modern Prolog implementation in Rust with enhanced error handling, comprehensive built-ins, and developer-friendly features.
The name NeoRusticus carries deep meaning that reflects the project's philosophy and aspirations:
The "Neo" prefix represents the modern, experimental approach to logic programming. It suggests evolution beyond traditional Prolog into areas like:
"Rusticus" has multiple layers of meaning:
Historical Depth: References Junius Rusticus, the Stoic philosopher and teacher of Marcus Aurelius. This connection is perfect for logic programming, which has deep philosophical roots in formal reasoning and logical inference—core concepts in Stoic philosophy.
Earthy Practicality: In Latin, "rusticus" means "of the countryside"—practical, grounded, and unpretentious. This fits both Rust's earthy, no-nonsense approach to systems programming and the project's focus on building something genuinely useful rather than merely academic.
Academic Gravitas: The name sounds scholarly and distinctive, appropriate for a serious exploration of language implementation and logic programming concepts.
Experimental Spirit: The "rough around the edges" connotation captures the experimental nature of this AI-assisted development project—it's a work in progress, a learning journey, not a polished commercial product.
Together, NeoRusticus embodies the vision of bringing classical logic programming wisdom into the modern era through Rust's safety and performance, while remaining open to experimental evolution.
The Psi (Ψ) symbol serves as Neorusticus's logo, chosen for its rich symbolic meaning:
Psi represents the mind, consciousness, and mental processes—perfect for a system that performs logical reasoning and artificial intelligence.
In computer science and AI, Psi often symbolizes intelligent systems, logical inference, and computational thinking.
The symbol's Greek origins echo the classical foundations of logic (Aristotle, Stoics) while the clean, geometric form represents modern computational precision.
The elevated, distinctive shape suggests rising above traditional limitations—fitting for a project that might evolve beyond conventional Prolog into experimental territories.
The Psi symbol perfectly captures Neorusticus's essence: a bridge between ancient wisdom and modern innovation, between human reasoning and artificial intelligence, between classical logic and experimental possibilities.
Neorusticus serves multiple ambitious goals that go beyond just building another Prolog implementation:
Rather than learning Rust through tutorials and toy examples, this project explores advanced Rust concepts—pattern matching, error handling, lifetimes, zero-cost abstractions, and memory safety—through a substantial, practical implementation. Every design decision provides deep insights into what makes Rust unique for systems programming.
Building a complete Prolog interpreter from scratch—lexer, parser, unification algorithm, and execution engine—provides intimate knowledge of how logic programming languages work. This includes understanding SLD resolution, backtracking, cut operations, and the subtleties of variable scoping and renaming.
Neorusticus is designed as a foundation for exploring advanced logic programming concepts and experimental features. The modular architecture allows for future expansion into areas like:
This project serves as a comprehensive case study in AI-assisted software development, with AI tools playing dual roles:
The goal is to evaluate how effectively AI can contribute to complex software projects when working with a technical leader who provides direction, requirements, and quality oversight. This collaboration model represents a new paradigm in software development that's worth studying and documenting.
This multi-faceted approach makes Neorusticus both a learning vehicle and a research platform, demonstrating the potential of combining human expertise with AI capabilities to tackle ambitious technical projects.
_ is distinct!Add this to your Cargo.toml:
[dependencies]
neorusticus = "0.1.0"
Or install the CLI tool:
cargo install neorusticus
use neorusticus::PrologEngine;
fn main() {
let mut engine = PrologEngine::new();
// Add some facts
engine.parse_and_add("parent(tom, bob).").unwrap();
engine.parse_and_add("parent(bob, ann).").unwrap();
engine.parse_and_add("parent(ann, sue).").unwrap();
// Add a rule
engine.parse_and_add("grandparent(X, Z) :- parent(X, Y), parent(Y, Z).").unwrap();
// Query the database
let solutions = engine.parse_query("grandparent(tom, sue).").unwrap();
println!("Solutions found: {}", solutions.len());
// Query with variables
let solutions = engine.parse_query("grandparent(tom, X).").unwrap();
engine.print_solutions(&solutions, &["X".to_string()]);
}
cargo run --example interactive
=== Neorusticus Prolog Interactive Shell ===
Enter Prolog clauses (ending with .) or queries (ending with ? or .)
Type 'help' for commands, 'quit' to exit.
?- parent(tom, bob).
true.
?- parent(tom, X).
X = bob.
?- X is 2 + 3 * 4.
X = 14.
?- append([1, 2], [3, 4], X).
X = [1, 2, 3, 4].
?- help
Commands:
help - Show this help message
quit - Exit the shell
stats - Show engine statistics
clear - Clear the database
?- X is 2 + 3 * 4. % X = 14 (respects precedence)
?- 5 > 3. % true
?- 10 =:= 5 + 5. % true (arithmetic equality)
?- 7 =\= 3. % true (arithmetic inequality)
?- append([1, 2], [3, 4], X). % X = [1, 2, 3, 4]
?- member(2, [1, 2, 3]). % true
?- length([a, b, c], X). % X = 3
?- var(X). % true (X is uninstantiated)
?- atom(hello). % true
?- number(42). % true
?- compound(f(x)). % true
% Each _ is automatically renamed to a unique variable
?- test(_, _, _). % Internally becomes test(_G1, _G2, _G3)
% Named underscore variables are preserved
?- foo(_temp, _). % _temp stays as _temp, _ becomes _G1
% Useful for pattern matching when you don't care about some values
?- member(2, [1, _, 3]). % Matches lists with any value in middle position
% Cut operation prevents backtracking
max(X, Y, X) :- X >= Y, !.
max(X, Y, Y).
?- max(5, 3, Z). % Z = 5 (doesn't try second clause)
?- lentgh([1, 2, 3], X).
Error: Undefined predicate: lentgh/2. Did you mean: length/2
?- appendd([1], [2], X).
Error: Undefined predicate: appendd/3. Did you mean: append/3
let mut engine = PrologEngine::with_config(100, 50); // max solutions, max stack depth
engine.parse_and_add("infinite(X) :- infinite(X).").unwrap();
// This will error instead of hanging:
let result = engine.parse_query("infinite(test).");
// Error: Stack overflow (depth 50) in predicate: infinite/1
use neorusticus::PrologEngine;
// Create engine with custom limits
let mut engine = PrologEngine::with_config(
1000, // Maximum solutions
200, // Maximum stack depth
);
// Or adjust limits later
engine.set_max_solutions(500);
engine.set_max_stack_depth(100);
use neorusticus::PrologEngine;
let mut engine = PrologEngine::new();
match engine.parse_and_add("invalid syntax here") {
Ok(()) => println!("Added successfully"),
Err(e) => {
engine.print_error(&e); // Pretty-printed error with context
}
}
The examples/ directory contains several demonstration programs:
cargo run --example basic_usage
Demonstrates core functionality with error handling.
cargo run --example arithmetic
Shows arithmetic predicates, functions, and mathematical sequences.
cargo run --example interactive
Full-featured REPL for experimenting with Prolog.
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Run specific test module
cargo test engine::tests
# Run integration tests
cargo test --test error_tests
Neorusticus is built with a modular architecture:
lexer - Tokenizes Prolog source code with position trackingparser - Recursive descent parser with operator precedenceast - Abstract syntax tree types for terms and clausesunification - Robinson's unification algorithm with occurs checkengine - Core execution engine with SLD resolutionbuiltins - Built-in predicates for arithmetic, lists, and controlerror - Comprehensive error types with suggestionsutils - Utility functions for pretty printing and analysis% Facts
parent(tom, bob).
likes(mary, wine).
% Rules
grandparent(X, Z) :- parent(X, Y), parent(Y, Z).
happy(X) :- likes(X, wine).
% Atoms
hello
'quoted atom'
% Numbers
42
-17
% Variables
X
_anonymous
CamelCase
% Lists
[]
[1, 2, 3]
[H|T]
[1, 2, 3|Rest]
% Compound Terms
foo(bar, baz)
person(name(john, doe), age(25))
% Arithmetic
X is 2 + 3 * 4 % Precedence: *, +
Y is (2 + 3) * 4 % Parentheses override
% Comparison
5 > 3 % Greater than
X =:= Y + 1 % Arithmetic equality
A = B % Unification
% Built-in Functions
abs(-5) % Absolute value
max(3, 7) % Maximum
min(10, 5) % Minimum
Neorusticus is designed for correctness and safety first, with reasonable performance:
Benchmarks (on modern hardware):
This project is primarily a personal learning experiment and AI-assisted development study. As such, I'm not accepting direct code contributions at this time, as the goal is to evaluate how effectively complex software can be developed through AI collaboration.
However, other types of contributions are very welcome and valuable:
Please open GitHub Issues for any of the above! I'm particularly interested in:
This project serves as a case study in AI-human collaboration for complex software development. The development process intentionally relies on AI tools as both advisor and code developer, with human oversight providing direction, requirements, and quality control. This approach aims to evaluate the current capabilities and limitations of AI-assisted development for substantial technical projects.
If you're interested in similar experiments or want to discuss the methodology, I'd love to hear from you!
Neorusticus is in active development. Current status:
If you use Neorusticus in academic work, please cite:
@software{neorusticus,
author = {Jonas Forsman},
title = {Neorusticus: A Modern Prolog Implementation in Rust},
year = {2025},
url = {https://github.com/fermatrox/neorusticus}
}
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.