what does" readin" predicate in prolog mean? - prolog

I have a question and I hope to help me:
what does" readin" predicate in prolog do?
I have searched in google but I have nothing
could you explain it to me with an example?
Regards.

I think you must be seeing readln not readin. The library predicate readln/1 reads tokens from an input line in the interactive SWI-Prolog console and makes a list of them. Most Prolog term reading predicates require a period to terminate input, but this predicate would include any terminating period in the list.
See here for a bit of documenation.

Related

SWI-prolog semweb library processing of URI

Being new to prolog I am reading existing code (as well as trying to write some code). Having some prior background in semweb I started to play with it and see something that is confusing me. Example assertion:
?- rdf_assert(ex:bob, rdf:type, foaf:'Person').
I also did find the following in the documentation:
Remember: Internally, all resources are atoms. The transformations
above are realised at compile-time using rules for goal_expansion/2
provided by the rdf_db library
Am I correct in assuming that somehow the library is treating the three URIs as atoms? I thought that the compiler would treat this as module_name:predicate, but that does not seem to be the case. If that is true, could you please provide a simple example on how this could be done in prolog?
Thanks
Prolog is not a functional language. This implies 2+3 does not evaluate to 5 and is just a term that gets meaning from the predicate that processes it. Likewise, ex:bob is just a term that has no direct relations to modules or
predicates. Only predicates such call/1 will interpret this as "call bob in the module ex".
Next to that, (SWI-)Prolog (most Prolog's, but not all) have term expansion that allows you to rewrite the term that is read before it is handed to the compiler. That is used to rewrite the argument of rdf/3: each appearance of prefix:local is expanded to a full atom. You can check that by using listing/1 on predicates that call rdf/3 using the prefix notation.
See also rdf_meta

Prolog existence_error for predicate in generated prolog file

I'm having a problem with a program that I'm writing. The program takes an input and generates a prolog program based on it. It generates something like this:
test(A):-condA(A),condB(A).
condA(val).
condB(val).
My problem is that sometimes, there is no condB(val), or condB anywhere in the program, except in the above definition of test. In that case, I got existence_error for condB, when I try to ask test(val), for example. Is there a way to add something to the prolog program that would define condB as false for all values of it's argument?
I'm sorry if this is stupid question, as I'm new to prolog.
You can tell the prolog processor that condB/1 is dynamic:
:-dynamic condB/1.
Answer to your question is simple.
condB(_):-fail.
the symbol '_' is free variable.

Stop Prolog program with predicate

I am looking for something like the predicate halt/0 or abort/0.
I do not want to use abort/0 because of the % Execution aborted message at the console and I do not want to use halt/0 because it terminates the Sicstus Prolog program.
Is there any other predicates that can be used to stop the program execution?
I already checked the documentation for this topic and I do not seem to find the result I want to see.
Maybe throw an exception with throw/1?
– mat
I managed to achieve what I wanted using that predicate.
Thank you mat.

How can I provide Prolog asks questions to me

Assume that we have prolog knowledge base like this:
guilty(X) :-
commits(X,Y),
crime(Y).
crime(murder).
crime(theft)
When I ask this question:
?- guilty(john)
I want that Prolog asks me a question like that:
is commits(john, murder) ?
and I answer no then
is commits(john, theft) ?
if I answer yes Prolog says
**yes**
How can I make something like this?
Thanks..
You need a modified proof engine, that when encounters an unknown fact query the user about.
Doing it with some generality can be an interesting task, Google for metainterpreter Prolog, if you are interested in this argument, the first link provides you the valuable page A Couple of Meta-interpreters in Prolog by Markus Triska, where you can learn more.
For your question, would suffice a rule
commits(Person, Crime) :-
crime(Crime),
format('is ~w ?', [commits(Person, Crime)]),
read(yes).
test:
?- guilty(john).
is commits(john,murder) ?no.
is commits(john,theft) ?yes.
true.
note that read/1 requires a dot to terminate the input.
You want an 'interactive shell' for your little reasoner. Building one is not difficult, but beyond the scope of a stackoverflow question. This tutorial builds one in the 2nd or 3rd lesson and generally answers this question. It calls facts like your user answers 'working storage'.
http://www.amzi.com/ExpertSystemsInProlog/
Prolog "executes" things from left to right. Try:
guilty(X) :-
crime(Y),
commits(X,Y).
crime(murder).
crime(theft)
So then guilty(X) depends on commits(X,murder) and/or commits(X,theft)

how to handle strings in prolog

i need to check if a string is available in given prolog statement
example
related('also-5','be-8').
i want to check if be is there in this statement how to do?
please give me some link to detailed tutorial on string handling in prolog
Relevant sections in the SWI-Prolog manual:
Analysing and Constructing Atoms
Representing text in strings

Resources