Вопрос

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