Connective Constraint

10 views
Skip to first unread message

zer0_gravity

unread,
Jul 3, 2009, 12:18:33 PM7/3/09
to CLIPSESG
Hi I would like to know how to bind the result of a connective
constraint to a variable. I tried many variation of using the &
constraint.

error message:
has constraint conflict which makes the pattern unmatchable

(defrule vb
(play TOPLEFT&TOPCENTER&TOPRIGHT ?k)
=>
(printout t ?k))

However when I replace the & constraint with the | constraint it work
(compiles without any errors) but logic it is incorrect. What I want
is for all three pattern to occur and stored the outcome in a variable
(?k).

CLIPS Support

unread,
Jul 3, 2009, 1:53:15 PM7/3/09
to CLIPSESG
(defrule vb
(play ?k&TOPLEFT|TOPCENTER|TOPRIGHT)
=>
(printout t ?k))

zer0_gravity

unread,
Jul 4, 2009, 10:36:57 PM7/4/09
to CLIPSESG
Hi one thing to add here. let's say for instance you have 3 facts
asserted and you created a rule to fire when all 3 facts are present
but I would like to know the value of the 3rd field in one out of the
three patterns.

(defrule position
(or

(and
(play TOP ?tmp&1)
(play CENTER 1)
(play BOTTOM 1))

)

=>
(printout t ?tmp crlf)

)

I want to use the connective constraint within a combination of OR
plus AND function and I would like to bind the 3rd field to a
variable (?tmp) in the first pattern. However the clips system
complains about the variable being undefined when I try to use the
variable (?tmp). If it is not possible to use the connective
constraint in this matter could you please suggest another way to
match all three pattern and bind the 3rd field to a variable using
connective constraints. thank you for responding.
> > (?k).- Hide quoted text -
>
> - Show quoted text -

zer0_gravity

unread,
Jul 4, 2009, 10:47:21 PM7/4/09
to CLIPSESG
Below is a variation of the code above but the clips sys. complains
about variable undefine.
please help me out here .thanks
(defrule position
(or


(and
(play TOP ?tmp&~0&1)
(play CENTER 1)
(play BOTTOM 1))


)


=>
(printout t ?tmp crlf)


)


> > - Show quoted text -- Hide quoted text -

Xin Liu

unread,
Jul 6, 2009, 11:53:45 AM7/6/09
to CLIP...@googlegroups.com
I am not sure what is the purpose of using the OR CE here since you have only one operand for it. Removing the OR CE leaves the same sematic while giving you the ability to use variable binding:
 
(defrule position

(and
(play TOP ?tmp&1)
(play CENTER 1)
(play BOTTOM 1))

=>
(printout t ?tmp crlf)


)
 
But I am not sure whether this is the sematic you want.

2009/7/5 zer0_gravity <zr...@hotmail.com>
--
/* Upcast */
IHuman liux0229 = new Chinese(1984.12.01.CE, China.Sichuan.Meishan);

/* Program to abstraction */
liux0229.live(LivingMode.Happily);

Johan Lindberg

unread,
Jul 8, 2009, 4:51:27 PM7/8/09
to CLIP...@googlegroups.com
Hi,

> Below is a variation of the code above but the clips sys. complains
> about variable undefine.
> please help me out here .thanks
> (defrule position
> (or
> (and
> (play TOP ?tmp&~0&1)
> (play CENTER 1)
> (play BOTTOM 1))
> )
> =>
> (printout t ?tmp crlf)
> )

How far off, from what you want, is the code that Gary suggested?

I'm having trouble understanding what you want to do from your example
and your descriptions. For example, how come you're using (or ...) and
(and ...) here? And, why are you using two connective constraints (~0
and 1) and a variable in the first pattern-CE?

BR
Johan Lindberg
jo...@pulp.se

Reply all
Reply to author
Forward
0 new messages