酷兔英语

章节正文
文章总共2页

fx

~



700

xfx

<, =, =.., =@=, =:=, =<, ==, ==, >, >=, @<, @=<, @>, @>=, =, ==, is



600

xfy

:



500

yfx

+, -, /, /, xor



500

fx

+, -, ?,



400

yfx

*, /, //, rdiv, <<, >>, mod, rem



200

xfx

**



200

xfy

^




Note that all operators can be redefined by the user, most commonlyaccidentally and with disastrous results.




 




or, logical disjunction, ;


The logicalconjunction (logical-and, ∧) of goals is achieved in Prolog by separating the goals by commas:


 


happy(X) :- rich(X), famous(X).


says that X is happy if X is rich and X is famous. What about logical-or, ∨, also called disjunction? If we want to say that X is happy if X is richor if X is famous, we have two possibilities:




  1. use two alternative rules


  2. use the ;operator (pronounced "or").




Option 1:


happy1(X) :- rich(X).
happy1(X) :- famous(X).


Option 2:


happy2(X) :- rich(X) ; famous(X).


Sometimes it is necessary, or at least advisable, to wrap parentheses ( ) around a disjunction in order to make clear what how the conjunctions and disjunctions interact. If you leave out the parentheses, Prolog has its own rules about the precedence of logical-and and logical-or, which might or might not correspond to what you intend. If you use parentheses, the things inside the parentheses are done first, so everything is crystal clear.




Option 3:


happy3(X) :- attractive(X), ( rich(X) ; famous(X) ).


This says X is happy3 if X is attractive, and X is either rich or famous:

happy3(X) ⇐ attractive(X) ∧ (rich(X) ∨ famous(X)).*



* The Prolog Dictionary wishes to acknowledge that a range of world religions and philosophies would not agree that the criteria specified for happy1, happy2, and happy3 are either necessary nor sufficient for happiness. The definitions given in this article, are, therefore, purely intended as Prolog programming examples, and should not be taken as a practical guide to life. Thank you.





 




output in Prolog


Output in Prolog is not always needed, as often the variable bindings return all the information that is required. If explicit output is required, a set of extra-logical built-in predicates is available.

These include:


 




  • write(X) which writes the term X to the current outputstream (which means the window on your workstation unless you have done something fancy).


  • print(X, …) which writes a variable number of arguments to the current output stream. If an argument is a string (like 'Hello world!n') then the string is printed without quotes, and any 'n' and 't' are interpreted as newline and tab, respectively. A newline is printed at the end of the printing operation.


  • prin(X, …) is like print except that it does not append a newline to the end of the output.


  • tab(N) prints N spaces to output - N should be a number.


  • nl starts a new line.


  • put(C) prints a single character to the current output stream. C might be bound to a number in the range 0 to 255, in which case the number is treated as a character code, and the equivalentcharacter is printed, or it might be bound to a character, e.g. C = 'a', in which case obviously the character is printed.





 



predicate

Used to refer to the functionality afforded by a Prolog procedure. In this dictionary, we tend to talk about procedures when the code is written by the programmer, but predicates when the functionality is built-in, as with member.


 




 




procedure


A procedure in Prolog is a group of clauses about the same relation, for example:


 



 



is_a_parent(Parent) :- father_of(Parent, _Child).
is_a_parent(Parent) :- mother_of(Parent, _Child).


 


Here, two clauses together define the condition for someone to be a parent - together they form a procedure.


 



See also underscore for the reason for putting an underscore (_) character at the front of the variable_Child.





 



 



query

A query is a list of one or more goals typed to the Prolog interpreter's ?- prompt, separated by commas, and terminated with a full stop (.). For example,

?- lectures(john, Subject), studies(Student, Subject).

is a query comprising two goals. Prolog tries to satisfy the goals, and if it manages to do this, the query is said to succeed. If not, the query fails.


If the query fails, Prolog types "false.". If it succeeds, Prolog either types the list of variable bindings it had to assume in order to make the query succeed, or, if no variable bindings were necessary, it types "true.".



If several variable bindings allow the query to succeed, then normally (i.e. in the absence of cuts) all the bindings will be typed out, one after the other, with the Prolog user typing a ; to let the Prolog system know that they are ready to see the next set of bindings.



 




  • concept [´kɔnsept] 移动到这儿单词发声  n.概念;观念;思想   (初中英语单词)
  • failure [´feiljə] 移动到这儿单词发声  n.失败;衰竭;破产   (初中英语单词)
  • obvious [´ɔbviəs] 移动到这儿单词发声  a.明显的;显而易见的   (初中英语单词)
  • relative [´relətiv] 移动到这儿单词发声  a.有关系的 n.亲属   (初中英语单词)
  • interpreter [in´tə:pritə] 移动到这儿单词发声  n.译员;解释者;翻译器   (初中英语单词)
  • supposed [sə´pəuzd] 移动到这儿单词发声  a.想象的;假定的   (初中英语单词)
  • standing [´stændiŋ] 移动到这儿单词发声  n.持续 a.直立的   (初中英语单词)
  • operator [´ɔpəreitə] 移动到这儿单词发声  n.操作者;接线员   (初中英语单词)
  • available [ə´veiləbəl] 移动到这儿单词发声  a.可用的;有效的   (初中英语单词)
  • comparison [kəm´pærisən] 移动到这儿单词发声  n.比较;对照;比喻   (初中英语单词)
  • computer [kəm´pju:tə] 移动到这儿单词发声  n.计算机;电子计算器   (初中英语单词)
  • treatment [´tri:tmənt] 移动到这儿单词发声  n.待遇;对待;治疗   (初中英语单词)
  • argument [´ɑ:gjumənt] 移动到这儿单词发声  n.辩论;争论;论证   (初中英语单词)
  • solution [sə´lu:ʃən] 移动到这儿单词发声  n.解答;解决;溶解   (初中英语单词)
  • program [´prəugræm] 移动到这儿单词发声  n.说明v.为…安排节目   (初中英语单词)
  • principal [´prinsəpəl] 移动到这儿单词发声  a.主要的 n.负责人   (初中英语单词)
  • normal [´nɔ:məl] 移动到这儿单词发声  a.正规的 n.正常状态   (初中英语单词)
  • achieve [ə´tʃi:v] 移动到这儿单词发声  vt.完成;达到;获得   (初中英语单词)
  • crystal [´kristəl] 移动到这儿单词发声  n.水晶 a.水晶的   (初中英语单词)
  • attractive [ə´træktiv] 移动到这儿单词发声  a.有吸引力;诱人的   (初中英语单词)
  • acknowledge [ək´nɔlidʒ] 移动到这儿单词发声  vt.(公开)承认;感谢   (初中英语单词)
  • therefore [´ðeəfɔ:] 移动到这儿单词发声  ad.&conj.因此;所以   (初中英语单词)
  • purely [´pjuəli] 移动到这儿单词发声  ad.仅仅;简单地   (初中英语单词)
  • output [´autput] 移动到这儿单词发声  n.产品;产品;计算结果   (初中英语单词)
  • stream [stri:m] 移动到这儿单词发声  n.河 vi.流出;飘扬   (初中英语单词)
  • character [´kæriktə] 移动到这儿单词发声  n.特性;性质;人物;字   (初中英语单词)
  • obviously [´ɔbviəsli] 移动到这儿单词发声  ad.明显地;显而易见地   (初中英语单词)
  • absence [´æbsəns] 移动到这儿单词发声  n.不在,缺席;缺乏   (初中英语单词)
  • system [´sistəm] 移动到这儿单词发声  n.系统,体系,制度   (初中英语单词)
  • symbol [´simbəl] 移动到这儿单词发声  n.符号;象征   (高中英语单词)
  • proposition [,prɔpə´ziʃən] 移动到这儿单词发声  n.提议;主张;陈述   (高中英语单词)
  • critical [´kritikəl] 移动到这儿单词发声  a.批评的;关键性的   (高中英语单词)
  • assumption [ə´sʌmpʃən] 移动到这儿单词发声  n.掌握;担任;假定   (高中英语单词)
  • infinite [´infinit] 移动到这儿单词发声  a.无限的,无穷的   (高中英语单词)
  • dependent [di´pendənt] 移动到这儿单词发声  a.依赖的;从属的   (高中英语单词)
  • emphasis [´emfəsis] 移动到这儿单词发声  n.强调;重点   (高中英语单词)
  • define [di´fain] 移动到这儿单词发声  vt.解释;说明;限定   (高中英语单词)
  • declaration [,deklə´reiʃən] 移动到这儿单词发声  n.宣布;宣言;申报   (高中英语单词)
  • external [ik´stə:nəl] 移动到这儿单词发声  a.外部的;外面的   (高中英语单词)
  • representation [,reprizen´teiʃən] 移动到这儿单词发声  n.描写;表现(法)   (高中英语单词)
  • strictly [´striktli] 移动到这儿单词发声  ad.严格地   (高中英语单词)
  • commonly [´kɔmənli] 移动到这儿单词发声  ad.一般地;通常   (高中英语单词)
  • correspond [,kɔri´spɔnd] 移动到这儿单词发声  vi.符合;相当;通信   (高中英语单词)
  • equivalent [i´kwivələnt] 移动到这儿单词发声  a.相等的 n.同等物   (高中英语单词)
  • procedure [prə´si:dʒə] 移动到这儿单词发声  n.过程;手续;方法   (高中英语单词)
  • prompt [prɔmpt] 移动到这儿单词发声  a.敏捷的 vt.促使   (高中英语单词)
  • logical [´lɔdʒikəl] 移动到这儿单词发声  a.逻辑(上)的   (英语四级单词)
  • arithmetic [ə´riθmətik] 移动到这儿单词发声  n.算术   (英语四级单词)
  • disastrous [di´zɑ:strəs] 移动到这儿单词发声  a.招致灾祸的;不幸的   (英语四级单词)
  • conjunction [kən´dʒʌŋkʃən] 移动到这儿单词发声  n.联合;巧合;接近   (英语四级单词)
  • alternative [ɔ:l´tə:nətiv] 移动到这儿单词发声  a.二中选一的 n.选择   (英语四级单词)
  • respectively [ri´spektivli] 移动到这儿单词发声  ad.各自地;分别地   (英语四级单词)
  • normally [´nɔ:məli] 移动到这儿单词发声  ad.正常情况下;通常   (英语六级单词)
  • accidentally [,æksi´dentəli] 移动到这儿单词发声  ad.偶然地   (英语六级单词)
  • advisable [əd´vaizəbl] 移动到这儿单词发声  a.合适的,得当的   (英语六级单词)
  • variable [´veəriəbəl] 移动到这儿单词发声  a.易变的 n.可变量   (英语六级单词)


  • 文章总共2页
    文章标签:词典  

    章节正文