Tuesday, April 10, 2012

Prolog: Reverse list of lists

i have problem with my prolog code. I need reverse all atomic elements of list.



Example: [1,2,[3,4]] -> [[4,3],2,1]



My solution:



myReverse([], []).
myReverse([H|T], X) :- myReverse(T, RT), myAppend(RT, H, X).


But it only give me: [[3,4],2,1]
I think, i need use is_list function and recursive call list if it's not atomic... but my prograss is stucked... can u guys know how to write it?





No comments:

Post a Comment