I am new to Prolog and I am trying to remove the last element from a list. The code I have tried:
removeLast([],[_]).
removeLast([_|T], [_|OT]):-removeLast(T, OT).
Obtained from here. I executed the code from SWi Prolog and I am getting a weird output ...
1 ?-
| removeLast(X, [1,2,3,4]).
X = [_G299, _G302, _G305] .
This is supposed to show [1,2,3], instead it is showing some numbers(?)
I don't know what am I doing wrong, why it is displaying in this format? I tried every Google combination I know of to search this term, although I saw people use this format directly in their queries like, parent(X, _G3248)
.
Update: Thanks to @lurker, modifying the code to the original format gives the output correctly:
removeLast([],[_]).
removeLast([X|T], [X|OT]):-removeLast(T, OT).
15 ?- removeLast(X, [1,2,3,4]).
X = [1, 2, 3]
But can someone explain, what is _G3240?