There's more than one way to do things | |
PerlMonks |
Re^2: Using RegExp backtracking to implement Prolog? :-)by BerntB (Deacon) |
on Oct 17, 2006 at 18:09 UTC ( [id://578864]=note: print w/replies, xml ) | Need Help?? |
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. :-)
In Section
Seekers of Perl Wisdom
|
|