prolog-coroutining

How to write/edit own coroutines in Prolog?

痞子三分冷 提交于 2019-12-13 17:55:21
问题 I would like to build my own coroutines in Prolog. I'd like to add some extra functionalities. 回答1: One possible solution would be to use the term-expansion mechanism provided by some Prolog systems and Logtalk to rewrite calls to e.g. the freeze/2 predicate to do the extra steps you want. One must be careful, however, to not expand a call to a predicate into another goal that calls the same predicate as goal-expansion is recursively applied until a fixed-point is reached. The Logtalk

Remove leading s(s(0)) in list

一笑奈何 提交于 2019-12-12 10:33:28
问题 (This is a followup to that question). How to write lead1(Xs,Ys) which is true, iff Ys is a suffix of Xs with all leading s(s(0)) terms removed. Thus instead of removing leading 0 s this question is now about removing leading s(s(0)) s. Compared to the original question, the difficulty lies here in handling cases of s(X) and s(s(X)) properly. 回答1: Here's a version with if_/3 and =/3: list_suffix([],[]). list_suffix([X|Xs],S) :- if_(X=s(s(0)), list_suffix(Xs,S), S=[X|Xs]). Queries with a

Guard clauses in prolog?

拜拜、爱过 提交于 2019-12-08 16:23:12
问题 Do they exist? How are they implemented? The coroutining predicates of SWI-Prolog ( freeze , when , dif etc.) have the functionality of guards. How do they fit in the preferred Prolog programming style? I am very new to logic programming (with Prolog and altogether) and somewhat confused by the fact that it is not purely declarative, and requires procedural considerations even in very simple cases (see this question about using \== or dif). Am I missing something important? 回答1: First a

freeze/2 goals blocking on variables that have become unreachable

北战南征 提交于 2019-12-04 03:20:45
问题 I made the following little program to determine if the memory used for goals like freeze(X,Goal) is reclaimed when X becomes unreachable: %:- use_module(library(freeze)). % Ciao Prolog needs this freeze_many([],[]). freeze_many([_|Xs],[V|Vs]) :- freeze(V,throw(error(uninstantiation_error(V),big_freeze_test/3))), freeze_many(Xs,Vs). big_freeze_test(N0,N,Zs0) :- ( N0 > N -> true ; freeze_many(Zs0,Zs1), N1 is N0+1, big_freeze_test(N1,N,Zs1) ). Let's run the following query... ?- statistics,

Logical Negation in Prolog

那年仲夏 提交于 2019-12-01 15:21:43
I've read quite a bit about Prolog's Negation by Failure where Prolog in order to prove that \+Goal holds tries to prove that Goal fails. This is highly connected with CWA (close world assumption) where for example if we query \+P(a) (where P is a predicate of arity 1) and we have no clues that lead to prove P(a) Prolog assumes (due to CWA) that not P(a) holds so \+P(a) succeeds. From what I've searched this is a way to solve classical logic weakness where if we had no clue about P(a) then we could not answer whether \+P(a) holds. What described above was the way of introducing non-monotonic

Logical Negation in Prolog

家住魔仙堡 提交于 2019-12-01 14:06:05
问题 I've read quite a bit about Prolog's Negation by Failure where Prolog in order to prove that \+Goal holds tries to prove that Goal fails. This is highly connected with CWA (close world assumption) where for example if we query \+P(a) (where P is a predicate of arity 1) and we have no clues that lead to prove P(a) Prolog assumes (due to CWA) that not P(a) holds so \+P(a) succeeds. From what I've searched this is a way to solve classical logic weakness where if we had no clue about P(a) then we