partial implementation of top-down datalog