2008 October 21th Tuesday (十月 二十一日 火曜日)

  Today a TV meeting will be held.  But we don't know when begin.  I hoped that it is not so later to cause our off-duty.
These days the "repeat" have puzzled me.  How to use it?

command_loop:-
    repeat,
    write('Enter command (end to exit): '),
    read(X),
    write(X), nl,
    X == 'end'.

  From the above example, I can run a loop as the manual explain.  However, it will begin another new loop after finish
a loop.  Yesterday evening, suddenly I got a inspiration.  I added a "cut"(!) operator at the end.

command_loop:-
    repeat,
    write('Enter command (end to exit): '),
    read(X),
    write(X), nl,
    X == 'end', !.

  Only to add a "cut"(!) operation at the end.  This morning I test it.  OK, it can run correctly as I wished.

| ?- command_loop.
Enter command (end to exit): abc.
abc
Enter command (end to exit): eee.
eee
Enter command (end to exit): end.
end

yes

  There are other programs.

nous(L, M) :- = [logic|M].

nous([logic|M]-M).

nous --> [logic].

  The above three all are same means.

| ?- nous([logic, a, b, c], R).

=> R = [a,b,c]

yes

| ?- nous(X,[a, b, c]).

=> X = [logic, a, b, c]

yes

| ?- nous(X,R).

=> X = [logic|R] % the "R" is pending.

yes

  From these small segments, we can know the different list and DCG's meaning.  In my eye, the "unification" is the key for Prolog.
Other technology is come from scheme language, such as tail recursion, list structure, and so forth.  That is why it is easy to implement
a prolog interpreter in scheme language.  In acutal, I have implemented it many years ago.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值