in reply to OT(ish) - Best Search Algorithm

A look at the Prolog modules should bring a suitable solution.
zaxo describes a similar scenario Perl and Prolog with a procedural sematics solution.