tags:

views:

587

answers:

4

Without thinking to much, it seems to me that a large set of Prolog's functionality could be implemented as relational calculus (a.k.a. SQL).

Has anyone heard of any tools to automatically convert Prolog to SQL?

+1  A: 

Short answer: No. Although, at Uni I had to take some algorithms linked in a procedural pseduo-code and put them into Prolog. I'm thinking through how it'd work in SQL and I don't think you'd get enough of the core functionality.

In terms of list traversal, I don't see how you can do it relationally. You'll need to lean heavily on procedural constructs for it to work (for/loops, if statements, break (or whatever the equiv is in SQL for the cut). Was that what you were thinking or did you have anohter idea of how you'd go about it?

Martin Clarke
Lists would be a real trick and might not even be possible.
BCS
+2  A: 

The mapping isn't very good. SQL, for example, doesn't do backtracking, unification, lists, or adhoc nested structures.

Prolog doesn't deal well with composite objects, indexes, etc.

I'd say it's a no-go.

MarkusQ
I don't think you would need backtracking or unification as thing would be generated from the other end (with joins) OTOH this would kill all arbitrary depth recursion
BCS
Without backtracking, unification, recursion, and lists there isn't a whole lot left of prolog. And you can't generate the same class of things with joins, unless you're thinking of writing self modifying SQL (queries that build queries) which I suppose is _possible_ but...
MarkusQ
+8  A: 

Yes, of course.

A premise for skeptics: any semi-decent book on database theory mentions Datalog (which is Prolog-like) and theorems which demonstrate that is possible to translate it to/from Relational Algebra (RA) (under specific restrictions).

SQL is not faithful to RA or relational calculi, but is enough to support Prolog:

MaD70
A: 

I would like to writte a SQL to prolog compiler... And I'am asking is this a right thing to do...

Thanks in advance, Robert...;) [email protected]

Robert