in reply to Using RegExp backtracking to implement Prolog? :-)

There is more than backtracking in a Prolog system.

You need a logical database with facts and clauses, and being able to call predicates there (that btw, can be recursive).

To make anything practical you also need arithmetic, tail recursion, the cut and being able to assert and retract clauses on the database.

  • Comment on Re: Using RegExp backtracking to implement Prolog? :-)

Replies are listed 'Best First'.
Re^2: Using RegExp backtracking to implement Prolog? :-)
by BerntB (Deacon) on Oct 17, 2006 at 18:09 UTC
    Each predicate is compiled down to a method which contains a RE. The subroutine returns true if it succeeds, false otherwise and a specific constant if it has run into a cut.

    Matched data etc is stored in the blessed object.

    For all predicates, there is a "master" method that dispatches calls to other predicates of the same name, depending on number of parameters.

    If a clause referenced a predicate, then code is inserted into the RE which calls the sub. Depending on the return value of the sub, the code fails/succeeds matching.

    At least, that was how far I have gotten in my planning.

    I don't know how to unsets unification when it do RE backtracking (there is no support for that in the (?{ }) construct?). And I probably have missed other stuff.

    This idea probably reminds more than me about the idi.. uhm, heroes which implemented logical circuits in the game of Life. :-)

    Update: Please don't flame me if I got the vocabulary wrong; it was a long time ago I read Prolog. :-)