Question

I'm new to stackoverflow and to Prolog.

I want to get the current year and use it in a comparison like 'BD > currentYear'. From the research I've been doing, I think i need to use 'use_module(library(system))' but i don't know how to...

Can you help me?

Thank you!

Was it helpful?

Solution

datime/1 in library(system) will do what you want, something like:

%% test.pl BEGIN
% Ensure datime/1 is available
:- use_module(library(system), [datime/1]).


current_year(Year) :-
    datime(datime(Year,_Month,_Day,_H,_M,_S)).

%% test.pl END

You can then call current_year/1, like so:

| ?- current_year(Year), Year >= 2012, write('It is 2012 or later\n').
It is 2012 or later
Year = 2012 ? 
yes
| ?- 

(Note that variables in Prolog must start with an upper case letter, so currentYear is not a valid variable name.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top