I'm currently testing tuProlog as a scripting language and a simple relational database to use in games. In case someone is interested here's my impressions.
tuProlog is a Prolog interpreter created in 100% pure Java code. The official site is here: http://www.alice.unibo.it/xwiki/bin/view/Tuprolog/
hosted by a research institute of an italian university. Last modification and download size is 2008-12-23 and 1.8M. The number of core files (excluding guis and extras) is around 80 classes. The documentation includes a pdf user guide (which i find very well written and complete) and the api documentation which is also very complete.
The scructure of the installation file 2p-2.1.1.zip:
It's refreshing to find a product like this, that is well organized, has a complete manual and doesn't force you to read source code or hack through a disorganized wiki in order to know how to use it.
tuProlog can be run double clicking on it's jar file (using a MacOSX) and a gui application will start. With this i can browse a theory, manage loaded libraries, enter queries to solve goals and see the results. In Prolog the source is called a theory which is a list of clauses. Running a program is solving a query goal which is the main method. Loading a library is like loading a package. This gui also let's me run a prolog program step by step and manage the methods (clauses) to spy (breakpoints). It's very sophisticated and user friendly for research stuff.
Let's see how it works for a basic method to find a member in a list.
member(X,[Y|R]) :- member(X,R).
Press the Set Theory button and the new theory is accepted. Now try to solve for the goal "member(1,[3,2,1])." by writing the text on the query field. The final dot is necessary. Press Enter and solution view shows:
Pressing the Next button shows there are no more solutions:
This programming language is a bit weird but i find it very useful to store game data and execute queries.
For example, i entered the following theory:
Notice we can mix structured data similar to XML with tabular data and still query information in the same maner.
Inventory can be understood as a table with a reference to the player actor. To know how if the player has any potions and what effect they have i used the query string "Id=player, actor(Id, name(N), _, _, _, _), inventory(Id, Q, item(potion, name(PN), effect(PE)))." and the result is:
Id / player N / x Q / 10 PN / potion_of_healing PE / heal
I didn't made any tests to performance but the idea i have is that this should be much slower than SQL and SQL would be much slower than using optimized data structures, but we can use Prolog just to store data textually and process it to an internal data structure like we would do with XML and XSLT.
Extending the language with libraries is easy and is very well explained in the manual. A library is a Java class that extends Library and provides methods that will be added as predicates, functors or directives to the theory. Libraries can be loaded and unloaded dynamically. The libraries provided are Basic, ISO, DCG, IO.
Using tuProlog directly as a scripting language for moders, even with a Prolog engine configured to use only builtin clauses, would not be safe. The alternative is to encode a scripting language in Prolog terms, validate scripts when loading and interpret them. It's very slow but it would give full control and safety options.
Resuming, my opinion is tuProlog may be a very good alternative to xml, xquery and xslt. As a scripting language for moding games it needs a lot of work to make it secure and efficient.