Convert list to term in Prolog

What is the best way to convert a Prolog list to a Prolog term (this is not a list), in terms of efficiency and using existing built-in predicates as much as possible?

The interface and usage examples will be as follows.

%% list_to_term(+List:list, +Functor:atom, -Term:term) % % Usage: % % ?- list_to_term([], myfunctor, Term). % Term = myfunctor. % % ?- list_to_term([a, b, [c], D, 2], myfunctor, Term). % Term = myfunctor(a, b, [c], D, 2). 

those. this list (which is actually a nested term) smoothes the term with the given name.

I am not saying that it makes sense to do this. (But if you think so, please provide us with your answer.)

+4
source share
1 answer

You need to use the operator =.. , for example:

 list_to_term(List, Functor, Term) :- Term =.. [Functor | List]. 
+8
source

All Articles