0

I'm trying to use a PROLOG script file with Rules
in Batch mode, (not interactive mode).

Using swi-prolog in Ubuntu Linux,
it works well in Prolog's interactive mode.

But how to run prolog in Batch mode? (not interactive mode).

So, the objective is to call swipl with a query argument
and see the results
as output in Terminal.

Ideally,
to also see in the Terminal output, which Rule(s) are "true" for each input query.

My prolog db.pl file:

likes(john,jane).    
likes(jane,john).    
likes(jack,jane).    

% and a single Rule below:    
friends(X,Y) :- likes(X,Y) , likes(Y, X).    

I tried to run in Terminal:

swipl -s db.pl -t friends(X,Y) 

where:

friends(X,Y)    

is the goal/query I want to evaluate via the Rule in db.pl.

Expected result:

john,jane    

Ideal output with "true" Rule numbers:

john,jane,Rule01

Actual result:

bash: syntax error near unexpected token `('  

Can not find a simple code example
on how to accomplish this objective in prolog...

choroba
  • 231,213
  • 25
  • 204
  • 289
user39150
  • 103
  • 8
  • 1
    That's because bash processes parentheses on the command line. You'll probably need to put the query in quotes: `... -t "friends(X,Y)"`. – lurker Jun 24 '18 at 14:08
  • 2
    You might also want to look at this: [How to run SWI Prolog from the command line](https://stackoverflow.com/questions/25467090/how-to-run-swi-prolog-from-the-command-line) – lurker Jun 24 '18 at 14:14
  • thank you, Lurker but: swipl db.pl -t "friends(X,Y)" single or double-quotes, just opens the interactive version of swipl...no luck with that solution... – user39150 Jun 24 '18 at 14:40
  • 1
    Right. You still need to tell it to execute your goal. Check the other link I provided. Also you can Google "swipl command line execution" or something similar. There are several useful posts on this topic. – lurker Jun 24 '18 at 15:53
  • Hi Lurker. Yes, checked it and it works with their "Hello World" string example. I'm sweating trying to make it work using and evaluating the query arg: 'friends(X,Y)' and then outputing the result of the call: swipl db.pl 'friends(X,Y)' – user39150 Jun 24 '18 at 16:04
  • 1
    do you want to put a 'halt' goal in after your query? Then prolog will exit so your back on the normal terminal? – user27815 Jun 24 '18 at 18:31
  • @user27815: Yep! That halt to exit swipl makes sense!. We need to avoid swipl opening in Terminal and "prompting" the user for input. The idea is that the query arg, - ie: 'friends(X,Y)' is passed to swipl as an argument. Then swipl outputs the result to Terminal and exits... – user39150 Jun 24 '18 at 18:47

0 Answers0