GENI的核心 -- 推理机(2)流程控制
1、细说fail、“!”与回溯
与其他语言相比,Prolog最大的特点,是它的回溯机制。
回溯机制,主要手段有2个,一是用谓词fail引发回溯,二是用特别谓词“!”(读作cut)取消回溯。
Prolog运用fail引发回溯,实现程序的循环,并运用“!”对回溯进行控制。
看一个典型示例:
FACTS
f(integer)
PREDICATES...
分类:
Web程序 时间:
2014-07-18 21:22:49
阅读次数:
243
/** * 根据id获取元素文本 * @param {String} id|元素id * return {Integer || String} text */function getText(id){ var text = $('#'+ id).text().replace(/(^\s*)|(\s*...
分类:
其他好文 时间:
2014-07-18 19:11:20
阅读次数:
199
Palindrome NumberDetermine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers b...
分类:
其他好文 时间:
2014-07-18 15:17:26
阅读次数:
201
Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are +, -, *, /.
Each operand may be an integer or another expression.
Some examples:
["2", "1", ...
分类:
其他好文 时间:
2014-07-18 11:19:56
阅读次数:
210
Reverse IntegerReverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321click to show spoilers.Have you thought about th...
分类:
其他好文 时间:
2014-07-18 09:34:59
阅读次数:
212
Factovisors
The factorial function, n! is defined thus for n a non-negative integer:
0! = 1
n! = n * (n-1)! (n > 0)
We say that a divides b if there exists an integer k such that
k*a =...
分类:
其他好文 时间:
2014-07-17 19:05:06
阅读次数:
235
竖直拍照if (Integer.parseInt(Build.VERSION.SDK) >= 8) { camera.setDisplayOrientation(90); } else { if (getResources().getConfiguration().ori...
分类:
移动开发 时间:
2014-07-17 14:34:49
阅读次数:
252
SQLite库能够解析大部分标准SQL语言。但它也省去了一些特性而且增加了一些自己的新特性。这篇文档就是试图描写叙述那些SQLite支持/不支持的SQL语法的。查看keyword列表。例如以下语法表格中,纯文本用蓝色粗体显示。非终极符号为斜体红色。作为语法一部分的运算符用黑色Roman字体表示。这篇...
分类:
数据库 时间:
2014-07-17 14:19:11
阅读次数:
487
一、扩展函数原型的更好办法://定义下面的通用方法
Function.prototype.method=function(name,func){
this.prototype[name]=func;
returnthis;
};
//使用上面的通用方法作为工具进行扩展,以免每次扩展都访问Function.prototype.XXX(that‘sugly).
Number.method(‘integer‘,fun..
分类:
编程语言 时间:
2014-07-17 09:44:42
阅读次数:
259
jqGrid的格式化是定义在语言包中·$jgrid={·...·formatter:{·integer:{thousandsSeparator:"",defaultValue:'0'},·number:{decimalSeparator:".",thousandsSeparator:"",decim...
分类:
其他好文 时间:
2014-07-16 23:43:21
阅读次数:
664