next up previous index
Next: Returning Values to Up: Using Tcl/Tk from Previous: Returning Values to

Calling Prolog from Tcl

  Prolog predicates can be called from Tcl/Tk scripts with the Tcl command

prolog   goal [module]
The goal argument specifies the Prolog predicate and its arguments using the Tcl syntax. It is a list, i.e. it must be grouped together with double quotes or braces. The first element of the list is the Prolog predicate name, subsequent elements are the predicate arguments. Before the Prolog call, the arguments are converted to Prolog terms as follows:   The prolog   command can call only predicates with these argument types. To call Prolog predicates with atoms or structures or other arguments it is necessary to use the call_prolog   command.  

Examples of prolog usage:

prolog true                        ;# call true/0
prolog {write a}                   ;# call write("a")
prolog {write {1 2 3}}             ;# call write([1, 2, 3])
set a 10; prolog "r $a 12"         ;# call r(10, 12)
prolog {p a b c} mod1              ;# call p("a", "b", "c") in mod1

When Tcl variables are used as arguments of the Prolog predicate,   there are two points to keep in mind:

The module argument of the prolog   command is optional, if omitted, it defaults   to eclipse.

[eclipse 71]: [user].
 p(X) :- printf("This is default %w in eclipse\n", X).
 :- module(mod1).
 p(X) :- printf("This is %w in module mod1\n", X).
 :- module(mod2).
 p(X) :- printf("Another %w in module mod2\n", X).
 user       compiled traceable 240 bytes in 0.00 seconds

yes.
[eclipse 72]: tcl 'prolog "p a"'.
This is default a in eclipse

yes.
[eclipse 73]: tcl 'prolog "p a" mod1'.
This is a in module mod1

yes.
[eclipse 74]: tcl 'prolog {p a} mod2'.
Another a in module mod2

yes.




next up previous index
Next: Returning Values to Up: Using Tcl/Tk from Previous: Returning Values to



Micha Meier
Tue Jul 2 09:49:39 MET DST 1996