Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
edited tags
Link
false
  • 10.3k
  • 13
  • 111
  • 225
edited tags
Link
Vincent Ramdhanie
  • 103.3k
  • 23
  • 143
  • 196
edited body
Source Link
URL87
  • 11.1k
  • 36
  • 112
  • 177

Having list append implementation in Prolog -

append([],X,X). append([H|T1],X,[H|T2]) :- append(T1,X,T2). 

Which gives on -

append([a,b,c],[d,e,f],X). 

The output -

X = [a,b,c,d,e,f]. 

I Wonderwonder how does it work , I tried to trace function calling but I didn't understand how T2 , which is the tail of a list , can be has as tail of X which in append([a,b,c],[d,e,f],X) calling had not defined yet . Can you clear up this recursion for me ?

Having list append implementation in Prolog -

append([],X,X). append([H|T1],X,[H|T2]) :- append(T1,X,T2). 

Which gives on -

append([a,b,c],[d,e,f],X). 

The output -

X = [a,b,c,d,e,f]. 

I Wonder how does it work , I tried to trace function calling but I didn't understand how T2 , which is the tail of a list , can be has as tail of X which in append([a,b,c],[d,e,f],X) calling had not defined yet . Can you clear up this recursion for me ?

Having list append implementation in Prolog -

append([],X,X). append([H|T1],X,[H|T2]) :- append(T1,X,T2). 

Which gives on -

append([a,b,c],[d,e,f],X). 

The output -

X = [a,b,c,d,e,f]. 

I wonder how does it work , I tried to trace function calling but I didn't understand how T2 , which is the tail of a list , can be has as tail of X which in append([a,b,c],[d,e,f],X) calling had not defined yet . Can you clear up this recursion for me ?

Source Link
URL87
  • 11.1k
  • 36
  • 112
  • 177
Loading