i\'m starting up learning prolog (i use SWI-prolog) and i did a simple exercise in which i have 2 lists and i want to calculate their intersection and union. Here is my code
If the aim is to just 'get the job done', then swi prolog has built in primitives for exactly this purpose:
[trace] 3 ?- intersection([1,3,5,2,4] ,[6,1,2], X). intersection([1,3,5,2,4] ,[6,1,2], X). X = [1, 2]. [trace] 4 ?- union([1,3,5,2,4] ,[6,1,2], X). X = [3, 5, 4, 6, 1, 2].