I need to give a list to a predicate and get back from it a term containing the elements of that list.
So I would have something like:
turn_into_struct(+List, -Term).
One thing that I did think about is to use nb_setarg/3 recursively for each element of the list, but this way I would need to instantiate the term with a specific arity and I couldn’t find how to do that.
You could find the length of the list first, construct the new term with dummy values, and then populate each argument either recursively or through backtracking (using
findall, for instance). I’ll fill in additional details if you need them (and as long as I’m not spoiling your own effort).There is a simpler one-line technique using SWI-Prolog’s
=..predicate, though.