Make namespace the default namespace temporarily?

#1

I recently turned one of my source files into a SWI-Prolog module. Now every time I want to execute a command in the interpreter I have to prepend the module name followed by a colon before the predicate I want to call as a goal.

Is there a way, at least temporarily, to add the module’s predicates to the global namespace, or some other method that will allow me to omit the module name from predicate references? This would make an interactive session with the SWI-Prolog interpreter more convenient.

#2

Just to make sure you did this since you did not note in your question and did not not give the code.

You did export the predicates in the module?

e.g.

:- module(pdf__parser,
    [
        parse_lines/0,
        parse_file/0
    ]).
#3

Yes, that’s when the issue started. Before the export I didn’t have to use the prefix.

#4

Not sure I get this. If you loaded the module from user space you should be able to call the exported predicates without prefixing. If you want to call one of the internal predicates you normally just make the call and the Do What I Mean will suggest to prefix the goal. Finally, you can use

?- module(mymodule).

to make the toplevel resolve all calls to mymodule instead of user. That was part of the Quintus module implementation. I hardly ever use that.

If this doesn’t work for you, please share a complete example run.

#5

Hi Jan,

It’s when I call an internal predicate.

Here is my module definition:

:- module(
	% Module name.
		tsll,
	% Exported predicates list.
		[
			execute_single_user_action/2
		]
	).

Here is what happens now when I call an internal predicate from the interpreter:

2 ?- move_player_to(player_1, X).
Correct to: "tsll:move_player_to(player_1,X)"?

As you can see, the interpreter is expecting the module prefix now (tsll). If I remove the module definition, this goes away.

#6

That is what you would expect, no? You decide to enter y, if you do it often you add ts11: as prefix or you use ?- module(ts11). You should only call private predicates for debugging and thus which of the alternatives to use depends a bit on how much trouble to have to get this debugged. In most cases that should be just a couple of times and I accept the correction suggestion.

1 Like
#7

I understand. But I was hoping for something I could do temporarily with debugging sessions so as to make typing easier; like something equivalent to the “using” namespace statements in some other languages. It looks like no so I’ll just forge on. Thanks for replying.

#8

When starting a new pl file, I always put the module declaration at start, usually named the same as the file, and then on REPL use the shorthand consult form ?- [some/folder/my_new_module].

When using PCEmacs, I find handy ^c^f (describe file) and subsequently ^c^m (make, ask for save if needed). It spares to reload explicitly the modified modules.

Hope this help.
Ciao, Carlo