Conditionals in Prolog -


i have predicates monthyear returns current month if month , year not supplied below.

monthyear(m,y) :-     get_time(stamp),     stamp_date_time(stamp, datetime, local),     date_time_value(month, datetime, m),     date_time_value(year, datetime, y). 

if month , year supplied return supplied month , year. achieve have written following code below.

cal(x,y,z1,z2):-     z1 x,     z2 y.  cal(x,y,z1,z2):-     x == null,     y == null,     monthyear(z1,z2). 

however sure code can improved , faced error

error: is/2: arguments not sufficiently instantiated 

how can go making work?.

x=1,y=2,cal(x,y,z1,z2). returns z1 = x z2 = y 

and

cal(x,y,z1,z2). returns z1 = 1, z2 = 2016 

you can use 2 versions of cal:

cal(x,y,z1,z2):-     z1 x,     z2 y.  cal(z1,z2):-     monthyear(z1,z2). 

if call cal(2, 2015, z1, z2)

z1 = 2, z2 = 2015. 

if call cal(z1, z2) (today)

z1 = 1, z2 = 2016. 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -