The beginner prologue will help you get the current time
I'm modifying Eliza's program http://cs.nyu.edu/courses/fall11/CSCI-GA.2110-003/documents/eliza.pl trying to get it to print out the system time when the user asks "What time is it? After a few hours reading through the 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 don't understand how I can 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 homework and it may seem silly to experts, but I am really new to Prolog programming, although I have quite a lot of experience in object oriented and functional programming. No matter what parameters I pass to the get_date_time_value (time, X) function, I always get an error. I spent the whole night on the hit parade, but nothing works. Any pointers would be great! Thanks to
source to share
From the structure, I think 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 don't know if this works. I have not tested it.
source to share
You have no idea what you mean by your rule. You may be trying to find the current time in the list where the term appears get_date_time_value(time,x)
: but is this term a function call? Prolog does not support this: just look at the sentence you give for the predicateget_date_time_value/2
(not a function), and what you see is a sequence of predicate calls. Thus, your rule should probably be specified in a condition, which is only true if a call to your predicate get_date_time_value/2
is made and the clause chapter and the call exchange variable pass information between them.
source to share