I have a list of complex terms with the same functor and arity, but different arguments. Something like this:
Elements = [element(a, 1), element(b,2), element(c,3)]
And from it I wish to generate a new list, containing only second arguments of the each complex term in the list, like this:
Numbers = [1,2,3]
Is there a way to design the predicate to solve this problem for any length of the input list?
element(_, N)
will provide all values ofN
on backtracking. Also, have a look atfindall
orsetof
. - lurkerelement(_,N)
, but I find out that I understand how to make use of it only for a known number of arguments, which is not the case here. I'll try to useforeach
&setof
, thanks for the advice. - Timofeyfindall
notforeach
. ;) If you show your attempts, you'll get more help on SO. :) - lurkerfindall
! Thank you, I'll post the solution. Now I'm wondering how to solve it with recursion. - Timofeyfindall(X,member(element(_,X), Elements),Numbers)
. - Timofey