[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Executing prolog queries from shell

From: Daniel Diaz
Subject: Re: Executing prolog queries from shell
Date: Tue, 10 Dec 2013 18:42:51 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1


there several ways to do what you want. Basically, you have to: 1) launch prolog, 2) consult your file, 3) execute your query, 4) save your results (on a file).

Since it is not clear what you want to do exactly I give you some (a lot of) pointers:

You can launch gprolog with special argument(s) to execute goal(s) (more or less immediately). See:
In that case you execute gprolog with the args from your python code.

You can write a PrologScript (shebang) basically start your source file with #!/usr/bin/gprolog --consult-file. See:
In that case you execute the script from your python code (don't forget the chmod u+x).

Use the :- initialization(....) directive to execute an initial goal. See:

To get the command-line arguments you can use for instanceargument_list(L)

To save the result of your query you can use streams and term I/O.
Term output:

To quit gprolog execute the goal: halt.

Finally, note that you can also compile your source file to native code with:

you can add options like

or even


Then execute it (from your python code) simply with:

NB: use :- intialization(YOUR INIT GOAL) and halt to control the start and the end of your Prolog application.


Le 10/12/2013 18:05, Antonios Antoniadis a écrit :

Hello everyone.

I started building the left hemisphere of my robot's brain with gprolog and I'm 
stuck on probably a very basic thing as I haven't touched prolog since uni. I 
want to execute/pass/pipe/whatever queries/code into prolog from the GNU/Linux 
shell and save/use the results. Like friends(bob,alice) to see if they are 
friends or whatever. I can run any shell command via python or the shell itself 
of course but what/how should I run (sysntax) to e.g. have gprolog use a 
specific file with my stored rules or whatever (complied I guess) and pass the 
query like an argument or input? Actually, is this possible at all?

I hope I didn't confuse you!

Thank you,

Antonios A.

Users-prolog mailing list

Ce message a ete verifie par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a ete trouve.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]