unification question

This is a discussion on unification question within the PROLOG forums in Programming Languages category; 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...

Go Back   Application Development Forum > Programming Languages > PROLOG

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-13-2008, 06:55 PM
garvin
Guest
 
Default unification question

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
Reply With Quote
  #2  
Old 08-13-2008, 08:19 PM
Cesar Rabak
Guest
 
Default Re: unification question

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.
Reply With Quote
  #3  
Old 08-14-2008, 03:42 AM
garvin
Guest
 
Default Re: unification question

> > 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

Reply With Quote
  #4  
Old 08-14-2008, 05:02 AM
Bart Demoen
Guest
 
Default Re: unification question

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
Reply With Quote
  #5  
Old 08-14-2008, 06:53 AM
garvin
Guest
 
Default Re: unification question

Thanks a lot!

regards,
Garvin
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 04:21 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.