Castor: Logic paradigm for C++
Traditional approach to problem solving with computers is all about instructing the computer exactly how to solve the problem. This is called the Imperative paradigm and is based on the Turing machine. Languages such as C, C++, Java, Fortran etc. are all rooted in this paradigm.
The Logic paradigm (LP) is a declarative programming model. Instead of instructing the computer how to solve a particular problem, we describe the problem domain as facts and rules. Using the problem domain description, the computer figures out how to solve specific problems within that domain. Once the domain has been described, many different problems within that domain can be solved without additional code. Describing the problem domain and the specific problems that need to be solved are tasks for a programmer.
Logic programming is one approach in computer science towards what is sometimes referred to as the Holy Grail of programming: "The user states the problem, the computer solves it".
Prolog is the best known programming language that supports logic programming. The computational model underlying LP is rooted in Predicate calculus. This is analogous to the Turing machine which is the computational model for the imperative paradigm.
Castor is a small, pure C++, all header library. It seamlessly integrates LP with the other programming paradigms supported by C++ such as OOP, generic programming, imperative etc. Blending LP into C++ enables new designs and programming techniques that are not available to purely LP approaches or pure OO approaches, but only feasible within a multiparadigm blend. A key design goal of Castor is to smoothly and efficiently blend Logic into the rest of C++ with minimal syntactic overhead.
Castor 1.1 is now available. The primary focus of v1.1 is to enrich Castor's support for general purpose programming and enable query expressions. Here is a comprehensive list of new features. See the video covering the new features. Castor is distributed under the MIT license. Send your questions, feedback and technical contributions to roshan AT mpprogramming DOT c o m.
Also available: Version 1.0.
Documentation
- Get started with this introduction to Logic Programming in C++ (draft). Also available in French.
- Reference manual for Castor.
- Design and implementation (revised on Feb 24th '08): describes how support for LP is provided using only a few lines of C++.
Videos
Introduction to LP in C++ (using Castor 1.0)
Castor 1.1 - New features (Part 1 of 2): Features continuing to evolve from 1.0.
Castor 1.1 - New features (Part 2 of 2): Brand new stuff. TLRs, Coroutines, Query Expressions and examples.
Past Talks
| BoostCon 2010 | May 2010. See session info. |
![]() |
At SD West: March 2009. See session info. |
| ACM, San Francisco Bay Area Chapter Jan 21, 2009. 7 PM. Cupertino, CA |
At ACM, San Francisco Bay Area Chapter. Venue: Oak Room at Hewlett-Packard campus, Cupertino. ACM meetings are free and open to all who wish to attend. Details. |
![]() |
Logic Paradigm for C++ at SD West 2008: See session details. |
| Northwest C++ Users Group April 16, 2008 Redmond, WA |
90 min session on Logic Paradigm for C++: Open to public! Bring Your own OBjects (BYOB) and logic will be provided in this 90 minute talk on general purpose declarative programming with the Logic paradigm (LP). In this code centric presentation, Roshan Naik takes you through the basics of LP, LP with Castor and Multiparadigm programming. See session details. |

