merge lists in lists with special format
merge lists in lists with special format
I have the following format in Prolog: cars([car([...])])
cars([car([...])])
I would like to merge two cars lists.
cars
I tried:
mergelist(cars(),L,L).
mergelist(cars([car(Car_i)|Cars_i]),Cars_j,cars([car(Car_i)|List])) :-
mergelist(cars(Car_i),Cars_j,cars(List)).
But it doesn't work.
I would like the following example to work:
mergelist(cars([car([type([95], 2.0), type([120], 5.0), type([121], 10.0)]),
car([type([95], 0.4), type([120], 1.0), type([121], 2.0)])]),
cars(car([type([95], 2.0)])),Result).
The output will be:
Result = cars([car([type([95], 2.0), type([120], 5.0), type([121], 10.0)]),
car([type([95], 0.4), type([120], 1.0), type([121], 2.0)])]),
cars(car([type([95], 2.0)]), car([type([95], 2.0)])).
How can I do it?
merglist(cars(), L, L).
cars(X)
X
mergelist(cars([car(Car_i)|Cars_i]),...) :-
cars(X)
X
mergelist(cars(Car_i),Cars_j,cars(List)).
merglist
cars(Car_i)
Car_i
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
merglist(cars(), L, L).has first argument iscars(X)whereXis a list.mergelist(cars([car(Car_i)|Cars_i]),...) :-has first elementcars(X)whereXis a list. However, in your callmergelist(cars(Car_i),Cars_j,cars(List))., the first argument tomerglisthere iscars(Car_i)andCar_iis not a list.– lurker
Jul 2 at 1:39