2012-11-06 38 views
1

我是新來的stackoverflow和Prolog。需要從系統中獲得當前年份序言

我想獲得當前年份,並將其用於比較'BD> currentYear'。 從我一直在做的研究,我想我需要使用'use_module(庫(系統))',但我不知道如何...

你能幫助我嗎?

謝謝!

回答

1

datime/1庫(系統)會做你想做的,是這樣的:

%% 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 

然後,您可以撥打CURRENT_YEAR/1,像這樣:

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

(注意變量在Prolog中必須以大寫字母開頭,所以currentYarar不是有效的變量名稱。)

+0

非常感謝你=)* – Cheerio

相關問題