Placeholders and variables

10 views
Skip to first unread message

hayri

unread,
Aug 13, 2010, 6:54:23 AM8/13/10
to ETALIS
Hi,
I just wrote a new predicate named "between_datime" (not committed
yet) which is quite simple and uses less_datime to check if a datime
ist between two other parameters. It works well but I have to give
irrelevant information (in my case) like year, month and day also
although I only want to compare the time (hours, minutes, seconds).

It looks like this:

between_datime(T1,T2,T3):-
less_datime(T2,T1),
less_datime(T1,T3),
!.

The question is how can I ignore the year-month-day input?

I tried following:

between_datime(T1,
datime(_,_,_,T2_H,T2_Min,T2_S),
datime(_,_,_,T3_H,T3_Min,T3_S)):-
less_datime(datime(_,_,_,T2_H,T2_Min,T2_S), T1),
less_datime(T1, datime(_,_,_,T3_H,T3_Min,T3_S)),
!.

This seems to be ok but doesn't help me solve my problem.
I also tried to use placeholders as I define my own events:

action(X) <- betw(X) where (
current_datime(D1),
between_datime(D1, datime(_,_,_,6,00,00), datime(_,_,_,10,59,00))
).

but I keep getting "ERROR: </2: Arguments are not sufficiently
instantiated".

Any ideas how to fix that?

Paul Fodor

unread,
Aug 13, 2010, 10:22:39 AM8/13/10
to eta...@googlegroups.com

Hi,

> The question is how can I ignore the year-month-day input?

Easily, use the same numbers for year, month and day.
Instead of:
     between_datime(D1, datime(_,_,_,6,00,00), datime(_,_,_,10,59,00))
in your rule, use:
     between_datime(D1, datime(2010,8,20,6,00,00), datime(2010,8,20,10,59,00))

We can also modify the rule to check if the datime is valid. I think
it should give an error if it's not valid or complete (like you got.
Anyway, we can do anything you need.

I added you as a developer to the project, so you can commit. We need
you to provide your full name (email Darko and I), acknowledge and
agree to the current licence of the project (comply with the license,
don't commit code that challenges or changes the terms of the license
and keep in touch with us when you change your contact details in case
we ever need the agreement of all developers for any reason (change of
license, etc.)).
Another thing, after any commit you make, I appreciate if you test the
regression tests in the examples directory (runs all examples and says
if they were passed).

Paul.

hayri

unread,
Aug 13, 2010, 10:53:46 AM8/13/10
to ETALIS
Hey Paul,

your suggestion wasn't proper for my case since I don't want to change
the date every day per hand. I found a similar solution though. I used
current_datime(datime(Y,M,D,H,Min,Sec) to get the current values for
year-month-day and used them as a placeholder.

I will try to commit my predicates as soon as I'm done with them. I
have another one which also gives me some trouble. It's actually a
simple predicate but when I try it in the prolog environment I get a
false as an answer. It looks like this:

set_datime(datime(Y, M, D,_H,_Min,_S), DT2, H, M, S):-
DT2 = datime(Y, M, D, H, M, S).

As you can see I give to the predicate a datime and a new datime
(object?) DT2 with new parameters H,M,S and try to override the hours-
minutes-seconds with my parameters. You would probably say that I
could find another solution for that but I want to know why this
doesn't work to be able to understand the way of working of Etalis a
bit more. So my question is why am I getting a false when I try this

12 ?- current_datime(datime(T1_Y,T1_M,T1_D,T1_H,T1_Min,T1_S)).

13 ?-
set_datime( current_datime(datime(T1_Y,T1_M,T1_D,T1_H,T1_Min,T1_S)),
DT1, 6, 00, 00 )
false.

What does false mean and in which case would I get a true?

I will send you an email soon for my contact information.

Paul Fodor

unread,
Aug 13, 2010, 11:49:28 AM8/13/10
to eta...@googlegroups.com
Hi,
Prolog is not a functional language. So, something like the following
doesn't work.

> set_datime( current_datime(datime(T1_Y,T1_M,T1_D,T1_H,T1_Min,T1_S)),
> DT1, 6, 00, 00 )

Some languages allow all kinds of reification structures, but this is
a simple case that doesn't need any kind of special constructs.
Just call the current_datime/1 relation and use the arguments to bind
variables and pass values.

?- current_datime(datime(T1_Y,T1_M,T1_D,T1_H,T1_Min,T1_S)),
set_datime(datime(T1_Y,T1_M,T1_D,T1_H,T1_Min,T1_S),DT1,6,0,0).

Paul.

Reply all
Reply to author
Forward
0 new messages