Given list of constants, how can you replace each instance of a constant with a variable? Like so:

```
[1,1,2,1,2,3]

```

=

```
[A,A,B,A,B,C]

```

This is my version:

```
f([],Seen0,Out,Out) :-
  write(Seen0).

f([H|T],Seen0,Out0,Out):-
  member(H/Var0,Seen0),
  append(Out0,[Var0],Out1),
  f(T,Seen0,Out1,Out).

f([H|T],Seen0,Out0,Out):-
  not(member(H/Var,Seen0)),
  append(Seen0,[H/Var],Seen1),
  append(Out0,[Var],Out1),
  f(T,Seen1,Out1,Out).

```

And runs like so:

```
?- f([1,1,2,1,2,3],[],[],O).
[1/_G31,2/_G58,3/_G118]
O = [_G31, _G31, _G58, _G31, _G58, _G118] .

```

And:

```
?- f([a,a,b,a,b,c],[],[],O).
[a/_G311,b/_G338,c/_G398]
O = [_G311, _G311, _G338, _G311, _G338, _G398]

```

Any other (better?) solutions?