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:
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:
[eclipse 77]: tcl 'prolog {write $tk_version}'. $tk_version yes. [eclipse 78]: tcl 'prolog "write $tk_version"'. 4.0
[eclipse 15]: tclsh. % set a {a b c}; set b {1 2 3} [1, 2, 3] % prolog "append $a $b X" calling an undefined procedure append("a", "b", "c", 1, 2, 3, _118) in module eclipse % prolog "append [list $a] [list $b] X"; puts $var(X) a b c 1 2 3
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.