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). has first argument is cars(X) where X is a list. mergelist(cars([car(Car_i)|Cars_i]),...) :- has first element cars(X) where X is a list. However, in your call mergelist(cars(Car_i),Cars_j,cars(List))., the first argument to merglist here is cars(Car_i) and Car_i is not a list.
– lurker
Jul 2 at 1:39


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.

Popular posts from this blog

How to add background colour in existing image using Swift?

What's the difference between DDS and SOME/IP?

Moria Casán