문제

How to convert this

fact( [a,b,c], [d,e,f], ..., [p, q, r] )

to a list of these elements?

Result:

[[a,b,c], [d,e,f], ..., [p, q, r]]
도움이 되었습니까?

해결책

list_fact_args(Fact,List) :- Fact =.. [fact|List].

=.. is a handy predicate that transforms the predicate on the left to a list with predicate name as the first member and its arguments as the latter members. Or a list on a right to the predicate on the left. Here fact denotes that it lists only the predicates named 'fact'.

다른 팁

Get your Prolog Manual or textbook and look up =.. / 2.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top