| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hello, Please suppose the following simple example. facts: tag(id,1). text(ab,4). tag(id,2). text(ab,5). When I ask the database ?- tag(X,Y),text(V,W). I get all 4 possible combinations of X,Y,V,W. but I only want to get X = id Y = 1 V = ab W = 4 and X = id Y = 2 V = ab W = 5 as result. How do I get this output with _one_ clause? regards, Garvin |
|
#2
| |||
| |||
| garvin escreveu: > Hello, > > Please suppose the following simple example. > > facts: > tag(id,1). text(ab,4). > tag(id,2). text(ab,5). > > When I ask the database > ?- tag(X,Y),text(V,W). > > I get all 4 possible combinations of X,Y,V,W. > > but I only want to get > X = id > Y = 1 > V = ab > W = 4 > > and > > X = id > Y = 2 > V = ab > W = 5 > > as result. > > How do I get this output with _one_ clause? > Describe in words a clause that would come out with these results and then convert it to Prolog. |
|
#3
| |||
| |||
| > > How do I get this output with _one_ clause? > > Describe in words a clause that would come out with these results and > then convert it to Prolog. In words it would be "just give out all facts like they are in the database" (but in one clause). Maybe if you don't want to tell me, you can point me to some tutorial. It is really important for me. No, it's not homework or something like that. regards, Garvin |
|
#4
| |||
| |||
| On Wed, 13 Aug 2008 15:55:41 -0700, garvin wrote: > tag(id,1). text(ab,4). > tag(id,2). text(ab,5). > > When I ask the database > ?- tag(X,Y),text(V,W). > > I get all 4 possible combinations of X,Y,V,W. > > but I only want to get [..] > How do I get this output with _one_ clause? > > regards, > Garvin t(X,Y,V,W) :- Tag = tag(X,Y), Text = text(V,W), findall(Tag,Tag,Tags), findall(Text,Text,Texts), nth0(N,Tags,Tag), nth0(N,Texts,Text). Cheers Bart Demoen |
|
#5
| |||
| |||
| Thanks a lot! regards, Garvin |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.