Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying all matches.

Status
Not open for further replies.

thelizardreborn

Programmer
Joined
Mar 18, 2007
Messages
1
Location
US
I am using prolog to act as a database. My facts are all of the structure relation(Name,Type,Weight), with weight being floats.

I want to write a rule and query to write all relations with a weight greater than an input weight to the screen. I can get it to write one, here is what I have so far.

relation(itemA,type1,1.0).
relation(itemB,type3,16.0).
relation(itemC,type2,23.0).

weighOver(Weight):-
relation(Name,_,X),X>Weight,write(Name).

I might add that I am a beginner to Prolog, as well as any other non-procedural language, so I am having to rework how I approach problems. If I have to scrap what I have so far and set things up a different way, that's ok.

Thanks in advance!
 
You will need to use a grouping predicate such as setof/3 like this:

setof(Name/Type/X, relation(Name,Type,X), Set),

where Set would be the List of all possible combinations. However I am not too sure how to filter out those possibilities where X is less than the weight specified
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top