I'm trying to solve a problem using difference lists (which I don't really understand well and 2 weeks worth of reading on the net hasn't changed that). Basically I want to determine the depth of the elements in a list, ie, if I were to ask
depth([a,b,[c,[],[d,e]],f], L)
Prolog would answer
L = [0,0,[1,1,[2,2]],0]
I realize this is wrong but I really just have no idea what's going on. Any help would be great thanks.
depth(L1, L2) :- depth(L1, L2, 0).
depth([], L2, 0).
depth([H|T], L2, N) :- depth(T, [L2|N], N1), N is N1 + 1.
depth([a,b,[c,[],[d,e]],f], L)
Prolog would answer
L = [0,0,[1,1,[2,2]],0]
I realize this is wrong but I really just have no idea what's going on. Any help would be great thanks.
depth(L1, L2) :- depth(L1, L2, 0).
depth([], L2, 0).
depth([H|T], L2, N) :- depth(T, [L2|N], N1), N is N1 + 1.