ProTcXl applications usually consist of a part written in Prolog and a part written in Tcl/Tk. Tcl/Tk scripts can be loaded after the initialisation with the Tcl source command, e.g. tcl 'source file'. In ECLiPSe files, nested compilation is always interpreted relative to the directory of the current file, which means that an application consisting of several files can always be moved to another location and no paths have to be changed. The argument of the source command, however, is interpreted relative to the current working directory, and so it may be necessary to use absolute pathnames. With ProTcXl , this can be avoided, though. There are two different cases:
For the latter case, the ProTcXl predicate tcl_source/0 can be used. It must be called as a query in a Prolog file. When it succeeds, it defines a predicate tcl_source/1 in the current module which executes the Tcl source command relative to the directory of this Prolog file.
As an example, let us define a library that makes the Tcl regexp command available to ECLiPSe . It consists of a Prolog file which loads the tk library and defines predicates to initialise and shutdown the regexp predicate as well as the predicate itself:
The Tcl file regexp.tcl is located in the same directory as regexp.pl, somewhere in the library path:% regexp.pl :- lib(tk). :- tcl_source. regexp_init :- tk([nodisplay]), tcl_source('regexp.tcl'). regexp_end :- tcl exit. regexp(Expr, String, Var) :- tcl('prolog_regexp {##} {##}', [Expr, String], Var), Var \== "".
puts "loading regexp.tcl..." proc prolog_regexp {expr string} { set res [regexp $expr $string var] if {$res == 1} { return $var } else { return "" } }
Now we can use this library:
[eclipse 1]: lib(regexp). ... /home/scorpio21/micha/src/tcl/eclipse/regexp.pl compiled traceable 316 bytes in 0.30 seconds yes. [eclipse 2]: regexp_init. loading regexp.tcl... yes. [eclipse 12]: regexp("[^0-9a-zA-Z](((0x)[0-9a-fA-F]+)|[0-9]*)[^0-9a-zA-Z]", "1a3 abc 0xa5 123", X). X = " 0xa5 "