首页 > 解决方案 > Adding prolog list elements to listbox items in c#

问题描述

My code finds facts based on value range:

ara_deger_price(L,H,Res) :-
   findall( (Id,B,C,D,Price,F,Points),
            ( table(Id,B,C,D,Price,F,Points),
              \+ Price = null, \+ Price = 'Price', Price > L, Price < H
            ),
            Res).

It gives a list result like so:

?- ara_deger_price(200,250,X).
X = [ (284, 'Viña Cobos 2011 Marchiori Vineyard Block C2 Malbec (Perdriel)', 'Argentina', 'Malbec', 215, 'Michael Schachner', 92), (349, 'Torbreck 2012 RunRig Shiraz-Viognier (Barossa)', 'Australia', 'Shiraz-Viognier', 225, 'Joe Czerwinski', 97)] ;
false.

What I want to do is add every element of this list to a C# listbox. I can access elements using nth0/3 but I want to access every one of them.

I tried this:

show_record([]).
show_record([A|B]) :- write(A), write("\n"), show_record(B).

Which prints every element to one line in the console. Can I redirect the result from console to the listbox or is there a way to access every element in Prolog?

标签: c#prolog

解决方案


我解决了这个问题,忘了提供更新。这是我用来解决问题的代码:

aralik_price(L,H,X):-ara_deger_price(L,H,Res), member(X,Res).

Res它从中获取列表ara_deger_price并找到每个成员并使用 X 变量将它们全部返回。在 C# 中,我可以通过简单地遍历 X 变量来获取所有成员。


推荐阅读