In principle there are three ways to interact with Hdrug:
SICStus Prolog Top-level
Command Interpreter
Graphical User Interface
The first two items are mutually exclusive: if the command interpreter is listening, then you cannot give ordinary SICStus Prolog commands and vice versa. The graphical user interface can be used in combination with both the SICStus Prolog Top-level or the command interpreter.
Prolog queries are given as ordinary Sicstus commands. This way of interacting with Hdrug can be useful for low level debugging etc. Using the command interpreter can be useful for experienced users, as it might be somewhat faster than using the graphical user interface.
The command-interpreter features a history and an alias mechanism. It includes a facility to escape to Unix, and is easily extendible by an application.
The command interpreter is started by the Prolog predicate r/0 The command interpreter command p halts the command interpreter (but Hdrug continues).
Commands for the command interpreter always constitute one line of user input. Such a line of input is tokenized into a number of *words using spaces and tabs as separation symbols. The first word is taken as the command; optional further words are taken as arguments to the command. Each command will define certain restrictions on the number and type of arguments it accepts.
Each word is treated as a Prolog atomic (either atom or integer, using name/2). In order to pass a non-atomic Prolog term as an argument to a command, you need to enclose the word in the meta-characters { and }. For example, the flag command can be used to set a global variable. For example:
16 |: flag foo bar
sets the flag foo to the value bar. As an other example,
17 |: flag foo bar(1,2,3)
sets the flag foo to the Prolog atom 'bar(1,2,3)'. Finally,
17 |: flag foo {bar(1,2,3)}
sets the flag foo to the complex Prolog term bar(1,2,3), i.e. a term with functor bar/3 and arguments 1, 2 and 3.
Also note that in case the {,} meta-characters are used, then the variables occurring in words take scope over the full command-line. For instance, the parse command normally takes a sequences of words:
18 |: parse John kisses Mary
In other to apply the parser on a sequence of three variables, where the first and third variable are identical, you give the command:
19 |: parse {A} {B} {A}
The special meaning of the {,} meta-characters can be switched off by putting a backslash in front of them. For example:
53 |: tcl set jan { piet klaas }
=> piet klaas
54 |: tcl puts jan
jan
The following meta-devices apply: All occurences of $word are replaced by the definition of the alias word. The alias command itself can be used to define aliases:
19 |: alias hallo ! cat hallo
20 |: $hallo
so command number 20 will have the same effect as typing
33 |: ! cat hallo
and if this command had been typed as command number 33 then typing
35 |: $33
gives also the same result.
Moreover, if no alias has been defined, then it will apply the last command that started with the name of the alias:
66 |: parse john kisses mary
67 |: $parse
Both commands will do the same task.
It is possible to add commands to the command interpreter. The idea is that you can define further clauses for the multifile predicate hdrug_command/3. The first argument is the first word of the command. The second argument will be the resulting Prolog goal, whereas the third argument is a list of the remaining words of the command (the arguments to the command).
:- multifile hdrug_command/3.
hdrug_command(plus,(X is A+B, format('~w~n',[X])),[A,B]).
Relevant help information for such a command should be defined using the multifile predicate hdrug_command_help/3. The first argument of this predicate should be the same as the first argument of hdrug_command. The second and third arguments are strings (list of character codes). They indicate respectively usage information, and a short explanation.
:- multifile hdrug_command_help/3.
hdrug_command_help(plus,"plus A B","Prints the sum of A and B").
For example, consider the case where we want the command rx to restart the Tcl/Tk interface. Furthermore, an optional argument of `on' or `off' indicates whether the TkConsol feature should be used. This could be defined as follows:
hdrug_command(rx,restart_x,L):-
rxarg(L).
rxarg([on]) :- set_flag(tkconsol,on).
rxarg([off]) :- set_flag(tkconsol,off).
rxarg([]).
hdrug_command_help(rx,"rx [on,off]",
"(re)starts graphical user interface with/without TkConsol").
without Val displays value of Flag; with Val sets Flag to Val
without Val displays value of Flag; with Val sets Flag to Val
ignores Words (comment). Note that there needs to be a space after %.
fcompiles(Files).
use_module(Files).
ensure_loaded(Files).
compile(Files).
reconsult(Files).
load(Files).
for each File, use_module(library(File)).
for each File, reconsult(library(File)).
for each File, compile(library(File)).
for each File, ensure_loaded(library(File)).
for each File, load(library(File)).
displays version information.
quits Hdrug.
break; enters Prolog prompt at next break level.
debug/0.
nodebug/0.
without Goal: quits command interpreter -- falls back to Prolog prompt with Goal: calls Goal. Normally you will need {} around the Goal. For example:
p { member(X,[a,b,c]), write(X), nl }
Command is executed by the shell. Note that the space between ! and Command is required.
No args: lists all aliases; one arg: displays alias Name; two args: defines an alias Name with meaning Val.
displays help on command Arg or flag Arg or predicate Arg or hook Arg; without Arg prints list of available commands, flags, predicates, or hooks.
displays help on command Arg or flag Arg or predicate Arg or hook Arg; without Arg prints list of available commands, flags, predicates, or hooks.
displays listing of all commands, flags, predicates or hooks respectively; without Class displays all help for all classes.
set spypoint on Module:Pred; Pred can either be Fun or Fun/Ar.
change working directory to Dir; without argument cd to home directory.
print working directory.
listing of directory contents
prints lexical hierarchy for Type; without Type, prints lexical hierarchy for top
(re)starts graphical user interface
halts graphical user interface
calls tcl command Cmd; what is returned by the tcl command will be printed on the screen after the => arrow.
75 |: tcl expr 3 * [ expr 5 + 4 ]
=> 27
Remember that { and } need to be prefixed with backlash since otherwise the Hdrug shell treats them. For instance
63 |: tcl expr 3+4
=> 7
sources Tcl source File
displays Objects with specified Format and Output; cf help on s_format, s_output and s_value respectively.
Specifies the Format of the s command.
i write/1;
j print/1 (default);
s semantics (third argument of o/3 object terms)
w words (second argument of o/3 object terms)
f Path display as a feature structure; the optional path is a sequence of attributes separated by colons (it selects the value at that path). The prefix of the path can be a sequence of integers seperated by / in order to select a specific node in the tree: this is only possible of the category is a tree datastructure with functor tree/3 where tree labels are specified in the first argument and lists of daughters are specified in the third argument.
T T is a tree-format, display as a tree with that format. Tree-formats are specified with the hook predicates graphic_path, graphic_label and graphic_daughter.
Specifies the Output of the s command.
user as text to standard output (default);
latex LaTeX; ghostview is used to display result;
tk in the canvas of the graphical user interface;
dot used DOT
clig uses Clig
Specifies the Objects to be shown form the s command.
ObjSpec will select a number objects (parser/generator results):
s 2 5 8 specifies the objects numbered 2, 5 and 8
s 4 + specifies the objects number 4 and above
s 3 - specifies all objects up to number 3
s 5 to 12 specifies all objects between 5 and 12
DefSpec will select a user_clause definition:
s l Fun/Ar specifies a listing of the Fun/Ar predicate.
ValSpec will specify a goal, and select an argument of that goal:
s [Module:]Fun/Ar [Pos]
The Module prefix is optional (user module is assumed if not specified); the optional Pos argument selects a specific argument to be printed. If no Pos argument is specified then the full goal is printed. For example, if you have the following predicate defined:
x23(f(16),g(17),h).
then the following commands are possible:
|: s x23/3
x23(f(16),g(17),h)
|: s x23/3 1
h
|: s user:x23/3 2
g17
displays type t=tree x=latex tree, tk=tk tree, clig=clig tree, dot=dot tree, none=textual information. No Type implies that top is used.
compares parsers on each sentence with key in Keys; without Keys, compares parsers on all availables sentences;
compares parsers on each sentence with key between I and J
compares generators on each lf with key in Keys; without Keys, compares generators on all available lfs;
compares generators on each lf with key between I and J
reset tables for parser/generator comparison for parser Parser or generator Generator; without argument reset tables for all parsers and generators
lists all sentences
lists all logical forms
print parser comparison overview
print parser comparison tables in detail
compares parsers on Sentences
compares generators on LF
compares generators on LF of object ObjNo
parses Sentence
parses Sentence
if Term is an integer ObjNo, then generate from LF of object ObjNo; otherwise Term is a semantic representation that is generated from
if Term is an integer ObjNo, then generate from LF of object ObjNo; otherwise Term is a semantic representation that is generated from
with File, compile_grammar_file(File); without File, compile_grammar.
with File, reconsult_grammar_file(File); without File, reconsult_grammar.
(re)starts graphical user interface with TkConsol feature
shows activity status of parsers and generator
with gm, List is a list of generators which are set to inactive status; without gm, List is a list of parsers which are set to inactive status
with gm, List is a list of generators which are set to inactive status; without gm, List is a list of parsers which are set to inactive status
with gm, List is a list of the only remaining active generators; without gm, List is a list of the only remaining active parsers;
graphically displays statistics for Parsers; without Parsers displays statistics for all parsers