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.
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.