Next: , Up: Debugger commands   [Contents][Index]


7.10.1 Interactive query commands

query module1 module2
cc_query module1 module2
io_query module1 module2

These commands allow you to type in queries (goals) interactively in the debugger. When you use one of these commands, the debugger will respond with a query prompt (‘?-’ or ‘run <--’), at which you can type in a goal; the debugger will then compile and execute the goal and display the answer(s). You can return from the query prompt to the ‘mdb>’ prompt by typing the end-of-file indicator (typically control-D or control-Z), or by typing ‘quit.’.


The module names module1, module2, … specify which modules will be imported. Note that you can also add new modules to the list of imports directly at the query prompt, by using a command of the form ‘[module]’, e.g. ‘[int]’. You need to import all the modules that define symbols used in your query. Queries can only use symbols that are exported from a module; entities which are declared in a module’s implementation section only cannot be used.


The three variants differ in what kind of goals they allow. For goals which perform I/O, you need to use ‘io_query’; this lets you type in the goal using DCG syntax. For goals which don’t do I/O, but which have determinism ‘cc_nondet’ or ‘cc_multi’, you need to use ‘cc_query’; this finds only one solution to the specified goal. For all other goals, you can use plain ‘query’, which finds all the solutions to the goal.


Goals can refer to variables in the current environment, which will be treated as inputs to the query. Any variables in the goal that do not exist in the current environment, and that do not start with an underscore, will be treated as outputs. For ‘query’ and ‘cc_query’, the debugger will print the bindings of output variables in the goal using ‘io.write_cc’. The goal must bind all of its output variables to ground terms, otherwise you will get a mode error.


The current implementation works by compiling the queries on-the-fly and then dynamically linking them into the program being debugged. Thus it may take a little while for your query to be executed. Each query will be written to a file named mdb_query.m in the current directory, so make sure you don’t name your source file mdb_query.m. Note that dynamic linking may not be supported on some systems; if you are using a system for which dynamic linking is not supported, you will get an error message when you try to run these commands.


You may also need to build your program using shared libraries for interactive queries to work. See Libraries for details of how to build with shared libraries.



Next: , Up: Debugger commands   [Contents][Index]