i was trying to create a function that takes a list of lists an gives back a new list with the elements of the original one but withoun depth.
f.e:
?- function([a,[b,c],d],X).
X = [a,b,c,d]
?- function([[a],[[b]],[c,[d]]],X).
X = [a,b,c,d]
and i found in a manual the following code:
function([],[]):- !.
function([H|T],[H|R]):- \+ lst(H), !, function(T,R).
function([H|T],L):- function(H,L1), function(T,L2),
append(L1,L2,T).
Unfortunately it says nowhere which function lst(H) is.
Plus i cannot understand what exactly lst() does and define it and as a result it comes out as undefined.
If anyone could understand how lst should be defined or simply give me an alternative about how to do what i’m trying,i’d be grateful..
It seems to me that lst(X) should be true iff X is a list. In SWI, an equivalent predicate is called is_list/1. In your code, + is used for negation, but i am familiar with
\+. (ah, i see, the site swallows the\)Edit: The last T in the last row should be L:
I tried it and it works in SWI.