我有下面的函数,如果传入的参数是一个合理的日期,它应该返回true,否则返回false。问题在于即使对于明显合理的日期它也会返回错误,我无法弄清楚它有什么问题。眼睛更锐利的人请帮助。这里是:我的函数有什么问题
fun reasonable_date(x: int*int*int) =
if #1 x > 0 andalso #2 x > 0 andalso #2 x <= 12 andalso #3 x > 0 andalso #3 x <= 31
then
if #2 x = 1 mod 2 andalso #2 x < 8 andalso #3 x <= 31 then true
else if #2 x = 0 mod 2 andalso #2 x >= 8 andalso #3 x <= 31
then true
else if #2 x = 0 mod 2 andalso #2 x < 8
then
if #2 x = 2 andalso (#3 x = 28 orelse #3 x = 29) then true
else if #2 x = 0 mod 2 andalso #3 x <= 30 then true
else false
else if #2 x = 1 mod 2 andalso #2 x > 8 andalso #3 x <=30 then true
else false
else false
待办事项你的意思是它总是返回false,或者它返回一些错误,但不是所有的合理日期? –
你可能会考虑用适当的'andalso'或'orelse'来替换一些'if-then-else'表达式。目前情况相当混乱。 –
它总是返回false。但现在没关系。它是固定的。谢谢 – guthik