Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have facts stored in different formats f.e.:

 fact(a,b,c)
 fact(d,e,f(g,h))
 fact(j(k,l),m,n(o,p,q))
 ...

.. always triple. I want to create a VIEW of the facts by only seeing the functor i.e.

 fact(a,b,c)
 fact(d,e,f)
 fact(j,m,n)
 ...

how do you do that .. ?

.. of course i want to be able to query them as normal facts ... omitting the hidden structure of-course (it will be interesting to take the hidden structure into account, but lets not complicate things for now)

PS> In general the most important thing is that the fact is a triple .. in the future I may change the possible structure of the items, but I want to be able to have simplified views where it is a triple. Any ideas along these lines are welcome.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
302 views
Welcome To Ask or Share your Answers For Others

1 Answer

factview(fact(A, B, C)) :-
    fact(Af, Bf, Cf),
    functor(Af, A, _),
    functor(Bf, B, _),
    functor(Cf, C, _).

Gives

?- factview(X).
X = fact(a, b, c) ;
X = fact(d, e, f) ;
X = fact(j, m, n).

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...