Well, I'm very new in prolog and I'm trying to solve some simple recursive problems like the following.
Implement firstKCharacters(Str, K, L)
function which gets the first K
characters of string Str
in the result string L
. I've figured out the following solution:
firstKCharacters(_, 0, _):- !.
firstKCharacters([X|L1], K, L):- append([X], S1, L),
X1 is K - 1, firstKCharacters(L1, X1, S1).
I'm confused about result:
?- firstKCharacters([a,b,c,d,e,f,g], 1, X).
X = [a|_1174]
Can someone explain what is the _1174
and why I'm getting a|_1174
isntead of a
?