I am trying constructing prolog program in which if list element is atom then after each atom insert test into the list and construct concrete list.
Say
for eg. addtest([1,2,3,a,2,v],L).
And should be : L= [1,2,3,a,test,2,v,test]
i am getting: L=[1,2,3,[a,test],2,[v,test]]
by implementing below logic.How remove/flatten nested parenthesis into the list so that i can get expected answer .
Program.
add([ ], L, L).
add([H|T], L, [H|M]) :- add(T, L, M).
addtest([], []).
addtest([H | T], [RH | RT]) :- (number(H)-> RH=H, addtest(T,RT)
;atom(H)-> add([H],[test],RH),addtest(T,RT)
).
if any one knows how to get rid of extra parenthesis or how to flatten list unto one level. please post solution/review.