meta-predicate

Goal expansion for an `if_/3` operator in Prolog

帅比萌擦擦* 提交于 2021-02-09 11:20:08
问题 I'm writing a tokeniser and I want to use if_/3 to preserve logical-purity in my code. The code looks like the following code 1 on the left—but I want it to look like the one on the right. if_(Cond1_1, % ( Cond1_1 Then1, % *=> Then1 if_(Cond2_1, % ; Cond2_1 Then2, % *=> Then2 if_(Cond3_1, % ; Cond3_1 Then3, % *=> Then3 if_(Cond4_1, % ; Cond4_1 Then4, % *=> Then4 if_(Cond5_1, % ; Cond5_1 Then5, % *=> Then5 Else5 % ; Else5 ) ) ) ) ). % ). To do the rewriting of (*=>)/2 to if_/3 in SWI-Prolog I

Prolog, Determine if graph is acyclic

倖福魔咒の 提交于 2020-01-04 05:20:15
问题 I need to define a predicate acyclic/1 that takes a graph in as input and determine if that graph is acyclic. So from my understanding graph1(a,b). graph1(b,c). graph1(c,a). Will return no and graph2(a,b). graph2(b,c). will return yes I made a predicate to determine if 2 nodes in a graph are connected and if so they will return yes. isConnected(X,Y) :- a(X,Z), isConnected(Z,Y). is there a way that I can use this to determine if a graph is acyclic? I do not want to use any predefined

Prolog binding arguments

你离开我真会死。 提交于 2020-01-02 16:19:02
问题 In sicstus prolog, there's a predicate: maplist(:Pred, +List) Pred is supposed to take just one argument - List element. How can I pass a 2-argument predicate, with first argument defined? In other languages it would be written as: maplist(pred.bind(SomeValue), List) 回答1: maplist(P_1, Xs) will call call(P_1, X) for each element of Xs . The built-in predicate call/2 adds one further argument to P_1 and then calls this with call/1 . To indicate that a further argument is needed, it is very

Prolog binding arguments

两盒软妹~` 提交于 2020-01-02 16:18:35
问题 In sicstus prolog, there's a predicate: maplist(:Pred, +List) Pred is supposed to take just one argument - List element. How can I pass a 2-argument predicate, with first argument defined? In other languages it would be written as: maplist(pred.bind(SomeValue), List) 回答1: maplist(P_1, Xs) will call call(P_1, X) for each element of Xs . The built-in predicate call/2 adds one further argument to P_1 and then calls this with call/1 . To indicate that a further argument is needed, it is very

Hilog terms in (XSB) Prolog

那年仲夏 提交于 2019-12-19 16:19:30
问题 Are Hilog terms (i.e. compounds having as functors arbitrary terms) still regarded as a powerful feature in XSB Prolog (or any other Prolog) ? Are there many XSB projects currently using this feature ? which of them for example ? I ask since as far as I understand higher order programming is equally possible using the ISO built-in call/N. Specifically, I would like to understand if XSB is using Hilog terms just for historical reasons or if Hilog terms have considerable advantages in

Pairwise relation over list

天涯浪子 提交于 2019-12-17 21:01:35
问题 The following higher order predicate succeeds if all pairs of the list's elements are true for a given relation. Is there a common or better, more intention revealing name for this relation? My original motivation for this name was that in clpfd, there is often a constraint all_different/1 which is described as being true, iff the elements are pairwise different . In fact, rather preferred to say the elements are all different, but I have been frequently corrected (by fellow Prolog

Prolog: Filtering a list?

我与影子孤独终老i 提交于 2019-12-17 02:24:33
问题 I'm currently working on a very short project on Prolog, and just got stuck trying to apply a "filter" I have created to a list. I have what you could call the filter ready, but I can't apply it. It'd be better if I illustrate: filter(A, B) ...outputs 'true' if certain conditions are met. filterList(A, [X, Y, Z]) ...outputs a list which includes all elements from the second argument that make the filter output false . (So if filter(A, X) is true, the output is [Y, Z] ). I have the "filter"

Prolog filter a list of all elements for which a custom goal fails

六月ゝ 毕业季﹏ 提交于 2019-12-10 20:51:59
问题 I am trying to write a predicate filter(List, PredName, Result) that filters a List of all its elements for which the goal PredName fails and subsequently returns the Result list. The predicate PredName/1 should be defined when calling the procedure filter/3 and could for example be: test(N) :- N >= 0 A query could then be made like following: ?- filter([-6,7,-1,0], test, L) L = [7, 0]; no 回答1: If you are using SWI-Prolog you could use the exclude predicate from the "apply" library 回答2: I'm

Relying on rule order

空扰寡人 提交于 2019-12-08 20:05:32
问题 To calculate the hamming distance between two lists of the same length, I use foldl(hamm, A, B, 0, R). with this definition of hamm/4 : hamm(A, A, V, V) :- !. hamm(A, B, V0, V1) :- A \= B, V1 is V0 + 1. The cut in the first rule prevents the unnecessary backtracking. The second rule, however, could have been written differently: hamm2(A, A, V, V) :- !. hamm2(_, _, V0, V1) :- V1 is V0 + 1. and hamm2/4 will still be correct together with foldl/5 or for queries where both A and B are ground. So

Hilog terms in (XSB) Prolog

谁都会走 提交于 2019-12-01 16:08:14
Are Hilog terms (i.e. compounds having as functors arbitrary terms) still regarded as a powerful feature in XSB Prolog (or any other Prolog) ? Are there many XSB projects currently using this feature ? which of them for example ? I ask since as far as I understand higher order programming is equally possible using the ISO built-in call/N. Specifically, I would like to understand if XSB is using Hilog terms just for historical reasons or if Hilog terms have considerable advantages in comparison to the current ISO standard. Within XSB, Hilog terms are very strongly connected to the module system