prolog how does a built in predicate get an existence_error? - prolog

so I have a prolog assignment that has to be tested with search algorithms provided by the teacher but I keep getting this error:
uncaught exception: error(existence_error(procedure,op/4),findall/3)
which I don't understand because op/4 and findall/3 are built in predicates, right? So how could they not exist?
Anyone has any advice on getting over this? Thanks

Related

Prolog procedure does not exist (cant run rules in prolog)

I am new to Prolog and using the SWISH SWI online PROLOG website. https://swish.swi-prolog.org/
I am trying a really basic program:
a('jae').
b('lii').
c('jackson').
happy(A):-sings(A).
happy(B):-dances(B).
goToPlay(C):-free(C).
trying to run happy(jae). gives the following error
procedure `sings(A)' does not exist
Reachable from:
happy(A)
Please help me solve this.
If submit the goal
happy(jae).
Then rule
happy(A) :- sings(A).
applies, which means that the next goal to be solved is
sings(A).
with A = jae.
Unfortunately the one-argument predicate sings/1 is nowhere to be found, so you get the same error as for a missing procedure in another programming language.
You have to define sings/1.

Prolog ERROR: Undefined procedure: transpose/2 (DWIM could not correct goal)

I have just started with Prolog for one of my classes so it's quite basic. I just had a doubt that does Prolog not have any inbuilt functions that can be used directly or should we always be writing a set of facts and rules first and then use them? I was trying to run this function:
?-transpose([[1,2,3],[4,5,6],[7,8,9]],Ts).
Which gave me this error:
ERROR: Undefined procedure: transpose/2 (DWIM could not correct goal)
So, basically, my question is, do I need to write how the transpose would work? I thought it was an inbuilt function ready to use.
P.S.: I am using: SWI-Prolog (threaded, 64 bits, version 7.6.0-rc1)
Of course it has quite a few built-in predicates (listed in http://www.swi-prolog.org/pldoc/man?section=builtin) but transpose is not one of them. If it's "for one of my classes so it's quite basic", most likely you are expected to write transpose yourself, especially if it's your first Prolog class.
There is one in clfpd library, see How to use predicate transpose in SWI-Prolog?.

prolog sort/4 undefined procedure built in

I am trying to use a supposedly built in procedure in SWI-Prolog.
The procedure in question is sort/4.
The thing is, when I try to use it in my program I get the following error:
ERROR: Undefined procedure: sort/4
ERROR: However, there are definitions for:
ERROR: msort/2
ERROR: sort/2
I don't understand because the documentation says its built-in, but Prolog doesn't know it. I really need to use this procedure
Would you know how to fix this issue ? I thought it was a matter of library and tried to add ":- use_module(library(lists))." at the beginning of my code but the situation remains the same.
Hope you can help me, have a good day
The sort/4 predicate as documented here is relatively new. If you get the latest stable or development version of SWI-Prolog it should be available. It is a built-in, not a part of a library.

Prolog beginner help get current time

I am modifying the Eliza program http://cs.nyu.edu/courses/fall11/CSCI-GA.2110-003/documents/eliza.pl
trying to get it to print the system time when user asks - What Time is it?
After hours of reading through manual I got my get_date_time_value() function to work.
As in
get_date_time_value(Key, Value) :-
get_time(Stamp),
stamp_date_time(Stamp, DateTime, local),
date_time_value(Key, DateTime, Value).
However I am at a loss as to how do I call this function from my rule which is defined as
rules([[time,0],[
[1,[_],0,
[please,do,not,get_date_time_value(time,x),.],
['I',dont,know,the,time,.]]]]).
Yes this is a homework assignment and this might sound silly to experts ,but I am really new to Prolog programming even though I have quite some experience in object oriented and functional programming.
No matter what parameters I pass to the get_date_time_value(time,X) function I am always getting an error.
I spent all night on a hit an trial approach ,but nothing I do works.
Any pointers will be great!!
Thanks
From the structure I guess it should look something like this:
rules([[time,0],[
[1,[_],0,
[it,is,HourLiteral,oclock,.],
['I',dont,know,the,time,.]]]]) :- get_date_time_value(hour, HourNumber), number_codes(HourNumber, HourString), atom_string(HourLiteral, HourString) .
I do not know if it works. I did not test it.
You do not give any idea of what you mean by your rule. Maybe you are trying to have the current time in the list where the term get_date_time_value(time,x) appears: but, is that term a call to a function? Prolog does not support that: just look at the clause you give for the get_date_time_value/2 predicate (not function) and what you see there is a sequence of calls to predicates. So your rule probably must given in a clause that holds only if the call to your get_date_time_value/2 predicate also holds, and the clause head and the call share variable(s) to pass information between them.

Prolog helloWorld not working

Silly question, but I'm trying to get this simple Prolog program working. I have written other small Prolog programs with no problem, but this one is giving me trouble:
test :- write 'test1234 test1234',nl,halt.
That's it. The file is saved as adventure1.pl. It is loaded into SWI-Prolog on Ubuntu with the command line option:
prolog -s adventure1.pl
When loaded into the Prolog interpreter I enter the following:
start.
However, Prolog says undefined procedure: test/0 (DWIM could not correct goal). What is the error here, is it somthing really simple. I wrote this because I have example programs that use a predecate named start which displays text, yet I can't even get this to work.
write 'test1234 test1234'
is a syntax error, as SWI-Prolog clearly indicates:
ERROR: /tmp/adventure1.pl:2:10: Syntax error: Operator expected
It should be
write('test1234 test1234')
(Of course, that won't solve the problem of start not working, because you've defined test.)

Resources