Prev Next Up Home Keys Figs Search New

GUI and Prolog

Appeared in Volume 8/4, November 1995

foxcj@essex.ac.uk
Christopher J. Fox
22nd September 1995

N.Parekh@dcs.warwick.ac.uk writes:

Does anyone know where I could get a GUI package that could be strapped onto an existing Prolog program? I am using IC-Prolog II under SunOS 4.1.x

I have produced GUIs for existing Prolog programs using Tcl/Tk. Tcl (pronounced 'tickle') is a scripting language and Tk is a Tcl based GUI toolkit (currently for X11). They are both available from SunSite (ftp://sunsite.unc.edu/pub/packages/tcl, with additional code in tcl-archive)) and its mirrors, (e.g.: ftp://sunsite.doc.ic.ac.uk/pub/packages). A full list of SunSites is available at http://www.sun.com/sunsite/index.html.

The most recent stable versions are Tcl 7.4p1 and Tk 4.0p1. Future releases (Tcl 7.5 and Tk 4.1) will also work under MS-Windows (3.1/95/NT) and MacOS.

Basically, I wrote a Tcl/Tk script that talked to Prolog down a bidirectional pipe. The main problem was that some Prologs (e.g. Sicstus) appear to send their prompt to stderr rather than stdout. I had to rewrite the Prolog code to send something down stdout before the prompt was 'printed'.

Also, you may find that you have to change some of your Prolog code to take account of the fact that GUIs are typically designed to allow users to input their choices in an arbitrary order.

It took me two or three weeks to write a graphical front-end for an existing Prolog program (a natural language interface to a relational database). That was the first time I had used Tcl/Tk.

A better way of adding a GUI to a command-line program might be to use Expect (or Expectk). Expect is an extension to Tcl (Tcl/Tk) specifically intended for adding a scripting language and GUIs to existing programs. Expect is available from ftp://ftp.cme.nist.gov/pub/expect/.

You might also be interested to know that there is a package, called ProTcl, for combining Sicstus Prolog (and Eclipse) with Tcl/Tk. It allows both Tcl expressions to be evaluated in Prolog, and rudimentary Tcl to Prolog callbacks [see http://www.ecrc.de/eclipse/html/protcl.html]. In addition, the latest version of Sicstus Prolog (3.0) has built-in support for Tcl/Tk [see http://www.sics.se/ps/sicstus.html].

There are books that describe Tcl/Tk and Expect:

Tcl and the Tk Toolkit, John K. Ousterhout, Addison-Wesley, 1994; ISBN 0-201-63337-X

Exploring Expect, Don Libes, O'Reilly and Associates, 1995; ISBN 1-56592-090-2

'Tcl and the Tk Toolkit' describes Tcl 7.3 and Tk 3.6, but is still applicable to the newer versions. There is information on the difference between Tk 3.6 and Tk 4.0 in the Tk 4.0 distribution. The book:

Practical Programming in Tcl and Tk, Brent Welch, Prentice Hall, 1995; ISBN 0-13-182007-9

gives examples that work with Tk 4.0.

For more information on Tcl/Tk and Expect, you could try:

http://www.cis.ohio-state.edu/hypertext/faq/usenet/tcl-faq/part1/faq.html

Prev Next Up Home Keys Figs Search New