bp myprog.out -g ``mymain(Output),writeln(Output)''
loads the binary file myprog.out and executes the goal
mymain(Output),writeln(Output)
instead of the default initial goal main.
You can also build a Prolog program as a standalone application by re-defining the main/0 predicate. The following definition is recommended:
main:-
get_main_args(L),
call_your_program(L).
where get_main_args(L) fetches the command line arguments as a list of atoms, and call_your_program(L) starts your program. If the program does not need the command line arguments, then the call get_main_args(L) can be omitted.
The second thing you need to do is to compile the program and let your main/0 predicate overwrite the existing one in the system. Assume the compiled program is named myprog.out. To let the system execute main/0 in myprog.out instead of the one in the system, you need to either add myprog.out into the command line in the shell script bp (bp.bat for Windows) or start the system with myprog.out as an argument of the command line as in the following:
bp myprog.out
For example, assume call_your_program(L) only prints out L, then the command
bp myprog.out a b c
gives the following output:
[a,b,c]
Neng-Fa Zhou 2012-01-03