users-prolog
[Top][All Lists]
Advanced

[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

Hi,

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:
http://gprolog.org/manual/html_node/gprolog007.html
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:
http://gprolog.org/manual/html_node/gprolog007.html#sec11
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:
http://gprolog.org/manual/html_node/gprolog022.html#initialization%2F1

To get the command-line arguments you can use for instanceargument_list(L)
http://gprolog.org/manual/html_node/gprolog051.html#argument-counter%2F1

To save the result of your query you can use streams and term I/O.
Streams: http://gprolog.org/manual/html_node/gprolog034.html
Term output: http://gprolog.org/manual/html_node/gprolog038.html#write-term%2F3

To quit gprolog execute the goal: halt.
http://gprolog.org/manual/html_node/gprolog042.html#abort%2F0

Finally, note that you can also compile your source file to native code with:
gplc my_app.pl--no-top-level--no-debugger

you can add options like
gplc my_app.pl--no-top-level--no-debugger

or even
gplc my_app.pl--min-size

See: http://gprolog.org/manual/html_node/gprolog009.html

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

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

Daniel

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
address@hidden
https://lists.gnu.org/mailman/listinfo/users-prolog



--
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]