1

I need to implement the predicate

term_variables

I need to get a term and return a list of variables (every variable only once).

for every new variable i check if its a member of a list if not then add the variable name to the list.

my problem is that when i save the variable in the list it gets saved a _g474 and i need to save it as the variable name X.

Is there any way to get the variables name?

Thanks


My Code:

term_variables(Term) :-
   Term=..L,
   term_variables(L, []).

term_variables([X| Xs], Vars):-
      compound(X),
      X=..L,
      term_variables(L, Vars)
   ;   
      var(X),
      not(member(X, Vars)),
      write(X),
      term_variables(Xs, [X|Vars])
   ;   
      term_variables(Xs, Vars).
term_variables([], _,).
false
  • 10,264
  • 13
  • 101
  • 209
ilan
  • 4,402
  • 6
  • 40
  • 76
  • Since many years, `term_variables/2` is a built-in predicate in SWI. So you cannot redefine it. Either you are using a very old version, or ... – false Aug 27 '16 at 20:15
  • I'm not trying to redefine it, i just need to implemented it... it needs to have a different name. – ilan Aug 27 '16 at 20:35

0 Answers0