Hi ,
I'm new to prolog and it's a bit difficult to understand some concepts, i was trying to connect list elements into one list con([[1,2,3],[a]],Result) into R=[1,2,3,a] , but the main problem i encountered was that i can't find a way to add up those list elements together i only succeed in adding the first one R=[1,2,3|G_624]:
add([],_). %we work with first element until list is empty
con([],_). %we do the same thing with the whole list
con([X|T],Result):-
add(X,Result); %Here Result changes to R=[1,2,3] instead of R=[[1,2,3]]and after another recursion should be R=[1,2,3,a] but for some reason Result does not add up :?
con(T,Result).
add([H|T],[H|R]):-
add(T,R).
What i am doing wrong? it's probably the adding changed result to Result, for some reason it doesn't add up more elements than one.
Hope you can help
I'm new to prolog and it's a bit difficult to understand some concepts, i was trying to connect list elements into one list con([[1,2,3],[a]],Result) into R=[1,2,3,a] , but the main problem i encountered was that i can't find a way to add up those list elements together i only succeed in adding the first one R=[1,2,3|G_624]:
add([],_). %we work with first element until list is empty
con([],_). %we do the same thing with the whole list
con([X|T],Result):-
add(X,Result); %Here Result changes to R=[1,2,3] instead of R=[[1,2,3]]and after another recursion should be R=[1,2,3,a] but for some reason Result does not add up :?
con(T,Result).
add([H|T],[H|R]):-
add(T,R).
What i am doing wrong? it's probably the adding changed result to Result, for some reason it doesn't add up more elements than one.
Hope you can help