冒号课堂§4.2:逻辑范式 - 编程入门网
{
if (other == null || this == other) return null;
if (parent == other) return isMale ? "son" : "daughter";
if (other.parent == this) return isMale ? "father" : "mother";
if (parent == null) // this是老祖宗
{
if (other.parent == null) return null;
if (other.parent.parent == this) return isMale ? "grandfather" : "grandmother";
return null;
}
if (other.parent == null) // other是老祖宗
{
if (parent.parent == other) return isMale ? "grandson" : "granddaughter";
return null;
}
// 非直系
if (isSibling(other)) return isMale ? "brother" : "sister";
if (parent.isSibling(other.parent)) return "cousin";
if (parent.isSibling(other)) return isMale ? "nephew" : "niece";
if (isSibling(other.parent)) return isMale ? "uncle" : "aunt";
return null;
}
public static void main(String[] args)
{
Person a = new Person(null, true);
Person b = new Person(a, true);
Person c = new Person(a, true);
Person d = new Person(a, false);
Person e = new Person(b, false);
Person f = new Person(b, true);
Person g = new Person(c, false);
Person h = new Person(d, true);
Person i = new Person(d, false);
Person j = new Person(d, true);
// 以下省略。。。
}
}
冒号课堂§4.2:逻辑范式(3)时间:2011-06-27 BlogJava xyz98“这段代码很平凡,毋需多言。再来看看逻辑式语言的做法。”冒号不愿过多地纠缠于细节,随即又换成了Prolog代码——
|
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |