See the links that @jkbkot gave for the complete descriptions. By way of very brief and very narrow examples:
parse_time
(note spelling - SWI Prolog predicate)
?- parse_time('Fri, 08 Dec 2006 15:29:44 GMT', Format, Time).
Format = rfc_1123,
Time = 1165591784.0.
?- parse_time('2013-10-12', Format, Time).
Format = iso_8601,
Time = 1381536000.0.
Using this, you can get a numerical representation of date/time and manage them numerically. The date string is a required input parameter (must be instantiated). So, unfortunately, parse_time
isn't useful for converting formats back and forth.
?- parse_time(D, iso_8601, 1381536000.0).
ERROR: atom_codes/2: Arguments are not sufficiently instantiated
bagof
and
^
likes(a,b).
likes(a,c).
likes(a,d).
likes(b,c).
likes(b,e).
?- bagof(X, likes(X,Y), L).
Y = b,
L = [a] ;
Y = c,
L = [a, b] ;
Y = d,
L = [a] ;
Y = e,
L = [b].
?- bagof(X, Y^likes(X,Y), L).
L = [a, a, a, b, b]
?- bagof(X-Y, likes(X,Y), L).
L = [a-b, a-c, a-d, b-c, b-e].
?- setof(X, Y^likes(X,Y), L). % provides the unique, sorted results
L = [a, b]
?- setof(X-Y, likes(X,Y), L).
L = [a-b, a-c, a-d, b-c, b-e].
findall
likes(a,b).
likes(a,c).
likes(a,d).
likes(b,c).
likes(b,e).
?- findall(X, likes(X,Y), L).
L = [a, a, a, b, b].
?- findall(X-Y, likes(X,Y), L).
L = [a-b, a-c, a-d, b-c, b-e].
@
The most common use of this symbol is in comparison predicates @</2
, @>/2
, etc. Example expressions of A<@B
and A>@B
are Prolog syntax errors.
?- 1 < 2.
true.
?- X=1, Y=2, X+Y<5.
true.
?- a < b.
ERROR: </2: Arithmetic: `a/0' is not a function
?- a @< b.
true.
?- a @> b.
false.
?- a < 1.
false.
?- [2,3,4] @< [2,3,5].
true.
?- [2,3,4] @< [2,3,3].
false.
?- foo(a,X) @< foo(b,Y).
true.
?- foo(b,X) @< foo(a,Y).
false.
Using @<
you don't necessarily have to use parse_time
if you want to compare date/time strings as long as their chronological order follows ASCII lexicographical order:
?- '2013-11-09' @< '2013-12-01'.
true.
?- '2013-01-12' @< '2012-12-12'.
false.
The @
comparison predicates can be quite handy. :)