How to set timestamp as an argument in a predicate?

Is there any way to use get_time(T) [which is built-in function] as an argument when I assert new facts to DB?
(I just want to compare between facts assertion time).


:- dynamic start/2.
start_interval(A) :- start(A, _), !, false.
start_interval(A) :- assert(start(A, get_time(T))).

Run Example:

Warning: c:/users/*****/desktop/prolog/
Warning:    Singleton variables: [T]
Welcome to SWI-Prolog (threaded, 64 bits, version 8.2.1)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. For legal details.

For online help and background, visit
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- start_interval(1).

?- start_interval(2).

?- listing(start).
:- dynamic start/2.

start(1, get_time(_)).
start(2, get_time(_)).


?- get_time(T).
T = 1598718310.038124.

Instead of “start(#, get_time(_))”, I would like to get to timestamp, which was made when I called start_interval(Num) at first.
(You can see also the output of get_time(T) when I call it)

Is it possible?
Maybe there is another way to compare between facts assertion time?

This is a common misunderstanding when beginning in prolog. Terms in prolog are not functions, so they do not return a value. To get the value you need to make the Term a Goal, and to do this the term needs to be in the body of the clause (or inside a call(…) but that is for later).

You would do something like this:

start_interval(A) :-
   assert(start(A, T)).

I would suggest you read the tutorial at first (at least the first 6-8 chapters), before you continue coding. Otherwise things will seem rather strange.

Hope this helps you out.

1 Like

This question was double posted at StackOverflow.

Thank you :slightly_smiling_face:

It was double by me.
I’m new with this kinds of forums and this language also, so I don’t know if there is big community familiar with Prolog.