0
votes

I am learning prolog, and I use swi-prolog as a compiler/interpreter. I have this hello world file:

:- initialization(main).
main :- format('Hello, world').

but when I try to compile it with swipl -o hello.exe -c hello.pro and run the binary hello.exe, it runs the goal first (main) but then returns me to the swi-prolog interactive environment. How do I just compile it so it's a functioning program without the prolog environment? I also tried adding halt at the end of main, but that doesn't compile at all. When I try that, the compiler prints "Hello, world" and then just stops compiling.

1
For clarity, are you saying you put halt after main inside the initialization directive? Or that you added halt as the tail call in defining main/0?hardmath
@hardmath as a tail call in defining main/0.tolUene

1 Answers

3
votes

I would:

  • remove the :-initialization directive
  • compile with: swipl.exe -nodebug -g true -O -q --toplevel=main --stand_alone=true -o hello.exe -c hello.pro

That should do the trick