simple example please, facts and query in one file

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

simple example please, facts and query in one file

Patrick
Hi Everyone

Sorry to ask this....

I am studying and making progress but I can't figure out the simplest thing.

I have been able to consult little database files and query but I don't
know how to list facts and query against them in the same file.

Could someone post a little example?

Sorry to bother everyone with this stupidity.

-Patrick



_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: simple example please, facts and query in one file

emacstheviking
Patrick,

To list the database use the "listing" predicate: 

It takes a parameter which you can use to narrow down what is listed as well. That should help you see what's in your database.

To make a query, just type it in at the prompt and hit RETURN... sounds obvious but that's all there is to ity unless I misunderstood your question!

Perhaps you'd care to post all or some (if it is large) of your facts and things that you have and then say what you want to query?

Sean.



On 19 November 2013 16:22, Patrick <[hidden email]> wrote:
Hi Everyone

Sorry to ask this....

I am studying and making progress but I can't figure out the simplest thing.

I have been able to consult little database files and query but I don't know how to list facts and query against them in the same file.

Could someone post a little example?

Sorry to bother everyone with this stupidity.

-Patrick



_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog


_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: simple example please, facts and query in one file

Patrick
Hi Sean

Thanks for answering my post and so quickly.

Sorry to drag down the list with this....

Here is an example.

I wrote in caps between the code

I found a simple database file on the web that called solar.pl

Here is what I typed to use it:

gprolog

GNU Prolog 1.4.4 (64 bits)
Compiled Nov  6 2013, 22:31:52 with gcc
By Daniel Diaz
Copyright (C) 1999-2013 Daniel Diaz

| ?- consult(solar) .
compiling /pat/prolog/solar.pl for byte code...
/pat/prolog/solar.pl compiled, 22 lines read - 1356 bytes written, 6 ms

(1 ms) yes
| ?- listing
.

% file: /pat/prolog/solar.pl

head :-
    body.

orbits(mercury, sun).
orbits(venus, sun).
orbits(earth, sun).
orbits(mars, sun).
orbits(moon, earth).
orbits(phobos, mars).
orbits(deimos, mars).

planet(A) :-
    orbits(A, sun).

satellite(A) :-
    orbits(A, B),
    planet(B).
satellite(moon).

yes
| ?-


NOW IF I TYPE:

orbits(mercury, sun) .

I GET:

yes

IF I TYPE:

| ?- orbits(mybutt, sun) .

no


ALL LOGICAL BUT IF I TYPE :

| ?- sally(tall) .
uncaught exception: error(existence_error(procedure,sally/1),top_level/0)
| ?-

I am not sure how I could add new facts without putting them in a separate file. I am wondering if the dynamic directive has something to do with this but I am still very shaky and was wondering if there was simple example of this.

Thanks again-Patrick







On 11/19/2013 11:27 AM, emacstheviking wrote:
Patrick,

To list the database use the "listing" predicate: 

It takes a parameter which you can use to narrow down what is listed as well. That should help you see what's in your database.

To make a query, just type it in at the prompt and hit RETURN... sounds obvious but that's all there is to ity unless I misunderstood your question!

Perhaps you'd care to post all or some (if it is large) of your facts and things that you have and then say what you want to query?

Sean.



On 19 November 2013 16:22, Patrick <[hidden email]> wrote:
Hi Everyone

Sorry to ask this....

I am studying and making progress but I can't figure out the simplest thing.

I have been able to consult little database files and query but I don't know how to list facts and query against them in the same file.

Could someone post a little example?

Sorry to bother everyone with this stupidity.

-Patrick



_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog



_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: simple example please, facts and query in one file

"Micha� Bieli�ski"
Dnia 19 Listopada 2013, 20:25, Wt, Patrick napisał:
> ALL LOGICAL BUT IF I TYPE :
>
> | ?- sally(tall) .
> uncaught exception: error(existence_error(procedure,sally/1),top_level/0)
> | ?-
>
> I am not sure how I could add new facts without putting them in a
> separate file.

Ah, you want to add facts directly from the interpreter!

Try this:

consult(user).

It means to consult a file which will be typed in its entirety from
keyboard by the user. Write all the facts you want and finish with end
sequence specific for your platform.  CTRL+Z, Enter on Windows or CTRL+D
almost everywhere else.

--
Michał Bieliński


_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog