Boost logo

Boost :

From: G. Wang (visionsoft_at_[hidden])
Date: 2004-09-12 22:41:53


Hi, all,

Unification and backtracking are the two key concepts of Prolog language.
Prolog language is one of the preferred ways to develop "intelligent"
software.

I am wondering how many people here are interested in a Boost Unification
and Backtracking Library (UBL). UBL will implement the unification and
backtracking feature with the help of both preprocessor meta-programming
(Boost Preprocessor library) and template meta-programming (MPL). With UBL,
you will define Prolog-like predicates right inside your C++ code.

========== Why do we need it? ===========================

1. a C++ and Prolog combined solution may not be convenient. You need to
write a lot of wrapper code to allow bi-directional communications between
Prolog code and C++ code. Standard Prolog is not an Object Oriented
Programming Language. As such, you need to write even more code to allow
Prolog to access C++ class instances. Worse yet, each prolog implementation
has its own way to interface with foreign languages. So your wrapper code
most likely would not be portable to other Prolog implementations.

2. Unlike C++, Prolog is not strong-typed. Folks in the C++ land too long
may not like anything that is not strong-typed.

3. C++ is a multi-paradigm language. At beginning, it was procedure
oriented. Then it's object oriented. During the past few years, functional
oriented programming in C++ and even aspect oriented programming in C++
become hot topics and real possibility. Now why don't we give C++ a logic
programming flavor?

4. UBL allows the programmer to switch back and forth among the
multi-paradigm seamlessly, therefore make it easier to combine the right
features of each paradigm to solve a given problem. Better yet, you do not
need to lean a new language (Prolog).

=========== Is UBL feasible?===================

The short answer is yes. I already have the prototype up and running in VC++
7.1. The 8-queen problem takes less than 28 seconds on my Athlon 2200+ to
find all answers. The prototype does have its fair share of shortcomings:

1. template based metaprogramming in general, and the prototype of UBL in
particular, takes too long to compile any non-trivial code. Or may not be
able to compile at all.

2. syntax wise UBL predicates are not as straight-forward or visually
appealing as the equivalent predicates in Prolog. Here is a predicate in
UBL:

BOOST_UBL_PREDICATE_2_( is_grandfather_of, Person, Person )
{
    BOOST_UBL_VARIABLES_3
 (
  Person, X
 , Person, Y
 , Person, Z
 );

    typedef clause< LHS<X, Y>
            , is_father_of< X, Z >
                , is_father_of< Z, Y >
> type;
};

Here is the equivalent predicates in Prolog:

is_grandfather_of(X, Y) :- is_father_of(X, Z), is_father_of( Z, Y).

3. In my plan, the Lambda library will provide the "fast-lane" between UBL
and your C++ instances, member functions and member variables. Of course,
that is not done yet.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk