How to find the set intersection from two lists using Prolog/Eclipse language? -


So before I start, here's the problem:

I have the example Xs = [ 1, 2,3] and list YS = [2,3,4] two common fundamental members of these two lists [2,3]. Therefore, I am trying to make a bill set interaction (Xs, YS, ZS) , as a result ([2,3]) will be bound to Z, and I try to do I am using Prologue language which can run on ECLIPs program on Windows and it should be used for loop iterator, any revision .

Even the code I have is:

  setIntersection (Xs, Ys, Zs): - (foreach (alpha, x), from ([ YS], [Head | Tail], Tail, []), Forchha (Bravo, YS) ((alpha =: = Head - -> Bravo = Head;)).  

The second version of the code I have is:

  set injection (xs, ys, zs): - (foreach (alpha, x), absolute (YES, za) (Bravo, YS), foreach (Charlie, Zs), do the alpha ((alpha = = = Bravo) -> Charlie Alpha ;;)).   

results (from second code):

 ? - Set inception ([1,2,3], [2,3,4], x). X = [2, 3, α 12] Yes (0.00 CPS)  

The results I get for the code given above are very strange.

Please help me Thank you!

I think you would like to do ECLIPS Declarative loops are needed, but only in case: do you have crossroads / 3> already in ECLiPSe Are aware of the effect? [Eclipse]: intersection ([1, 2, 3], [2, 3, 4]], x). X = [2, 3] Yes (0.00 CPU)

And here it is done in many ways with loops:

  setIntersection (Xs, YS, JS): - (from front (Xi, X), from ([], Jesprave, Zedsur, ZS), do the ultimate (YS) (Member Chuck (Xi, YS) - & gt; Zedsur = [Xi | ZsPrev]; ZsCurr = ZsPrev)  

Test run:

  [eclipse]: setIntersection ([1,2,3], [2,3 , 4], x). X = [3, 2] Yes (0.00 CPU)  

Elements are in opposite order that you provided in the example, but it does not make any difference with the set.

Why is "Pearl" in the header of the question, BTW?

You can reverse or sort the elements at the end.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -