bound variable doesn't work in pattern-matching

61 views
Skip to first unread message

Nima

unread,
Mar 15, 2012, 4:23:46 AM3/15/12
to CLIPSESG
Hi all,

I have a problem that can not find any reason for it!

in a pattern-matching, when I use a variable that Initialized
manually, pattern-matching work correctly.
But when use a variable that Initialized by binding, pattern-matching
doesn't work.

for example, first code, return 72 and work correctly:

first code:
--------------------------------------------------------------------------
(deffunction Pass-Search (?x)
?x)

(defglobal ?*OS* = Android)

(deffacts Mobile
(Mobile 71 Symbian)
(Mobile 72 Android))

(defrule Result
(Mobile ?name =(Pass-Search ?*OS*))
=>
(printout t ?name))
----------------------------------------------------------------------------



But when ?*OS* gets its value from user by using binding, it doesn't
work correctly:


------------------------------------------------------------------------------
(deffunction Pass-Search (?x)
?x)

(defglobal ?*OS* = Android)

(deffacts Mobile
(Mobile 71 Symbian)
(Mobile 72 Android))

(defrule Questions
(declare (salience 20))
=>
(bind ?response
(ask-question "2- What Is Your Favorite OS? (A/B/C)" "A.
Android B. Windows C. Symbian" a b c))
(if (eq ?response a)
then
(bind ?*OS* Android)))


(defrule Result
(Mobile ?name =(Pass-Search ?*OS*))
=>
(printout t ?name))

--------------------------------------------------------------------------------------------



ask-question is one of my functions.

I hope someone can help me.
Nima

Lode Hoste

unread,
Mar 15, 2012, 6:12:27 AM3/15/12
to clip...@googlegroups.com
Hi Nima,

Try double quoting the "a".

CLIPS> (eq "a" a)
FALSE
CLIPS> (eq "a" "a")
TRUE


2012/3/15 Nima <divoo...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups "CLIPSESG" group.
> To post to this group, send email to CLIP...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/CLIPSESG?hl=en
>
> --> IF YOU NO LONGER WANT TO RECEIVE EMAIL <--
> Visit this group at http://groups.google.com/group/CLIPSESG?hl=en
> Click on "Edit my membership" link.
> Select the "No Email" radio button.
> Click the "Save these settings" button.
>
> --> IF YOU WANT TO UNSUBSCRIBE <--
> Visit this group at http://groups.google.com/group/CLIPSESG?hl=en
> Sign in
> Click on "Edit my membership" link.
> Click the "Unsubscribe" button.
> Note: This appears to be the most reliable way to unsubscribe
>
> Alternately, send email to CLIPSESG-u...@googlegroups.com. You will receive an email which you must respond to as well to unsubscribe. Clicking the link mentioned in the unsubscribe reply does not appear to work reliably.

Nima

unread,
Mar 15, 2012, 11:18:35 AM3/15/12
to CLIPSESG
Hi Lode Hoste,

Unfortunately it didn't work.
I'm confuse and I do not know what to do!




On Mar 15, 1:12 pm, Lode Hoste <zill...@gmail.com> wrote:
> Hi Nima,
>
> Try double quoting the "a".
>
> CLIPS> (eq "a" a)
> FALSE
> CLIPS> (eq "a" "a")
> TRUE
>
> 2012/3/15 Nima <divoone0...@gmail.com>:
>
>
>
>
>
>
>
> > Hi all,
>
> > I have a problem that can not find any reason for it!
>
> > in a pattern-matching, when I use a variable that Initialized
> > manually, pattern-matching work correctly.
> > But when use a variable that Initialized by binding, pattern-matching
> > doesn't work.
>
> > for example, first code, return 72 and work correctly:
>
> > first code:
> > --------------------------------------------------------------------------
> > (deffunction Pass-Search (?x)
> > ?x)
>
> > (defglobal ?*OS* = Android)
>
> > (deffacts Mobile
> > (Mobile 71 Symbian)
> > (Mobile 72 Android))
>
> > (defrule Result
> > (Mobile ?name  =(Pass-Search ?*OS*))
> > =>
> > (printout t ?name))
> > ---------------------------------------------------------------------------­-
>
> > But when ?*OS* gets its value from user by using binding, it doesn't
> > work correctly:
>
> > ---------------------------------------------------------------------------­---
> > (deffunction Pass-Search (?x)
> > ?x)
>
> > (defglobal ?*OS* = Android)
>
> > (deffacts Mobile
> > (Mobile 71 Symbian)
> > (Mobile 72 Android))
>
> > (defrule Questions
> > (declare (salience 20))
> > =>
> > (bind ?response
> >      (ask-question "2- What Is Your Favorite OS? (A/B/C)" "A.
> > Android     B. Windows     C. Symbian" a b c))
> > (if (eq ?response a)
> > then
> > (bind ?*OS* Android)))
>
> > (defrule Result
> > (Mobile ?name  =(Pass-Search ?*OS*))
> > =>
> > (printout t ?name))
>
> > ---------------------------------------------------------------------------­-----------------
>
> > ask-question is one of my functions.
>
> > I hope someone can help me.
> > Nima
>
> > --
> > You received this message because you are subscribed to the Google Groups "CLIPSESG" group.
> > To post to this group, send email to CLIP...@googlegroups.com
> > For more options, visit this group athttp://groups.google.com/group/CLIPSESG?hl=en
>
> > --> IF YOU NO LONGER WANT TO RECEIVE EMAIL <--
> > Visit this group athttp://groups.google.com/group/CLIPSESG?hl=en
> > Click on "Edit my membership" link.
> > Select the "No Email" radio button.
> > Click the "Save these settings" button.
>
> > --> IF YOU WANT TO UNSUBSCRIBE <--
> > Visit this group athttp://groups.google.com/group/CLIPSESG?hl=en

CLIPS Support

unread,
Mar 15, 2012, 12:08:49 PM3/15/12
to CLIPSESG
Read through section 6 of the Basic Programming Guide which describes
how globals work: http://clipsrules.sourceforge.net/OnlineDocs.html

Use facts to pass information from one rule to another:

(defrule Questions
(declare (salience 20))
=>
(bind ?response
(ask-question "2- What Is Your Favorite OS? (A/B/C)" "A.
Android B. Windows C. Symbian" a b c))
(if (eq ?response a)
then
(assert (OS Android))))

(defrule Result
(Mobile ?name ?OS)
(OS ?OS)
=>
(printout t ?name))

Nima

unread,
Mar 15, 2012, 1:28:41 PM3/15/12
to CLIPSESG
Thanks alot!
It worked corectly very nice.
Thanks you again.

Only one problem remained.
If pattern-matching was true and pattern matched with facts in
knowledge base, I want in out put only 5 facts (for example) be
printout for ?name, not all of them. (Meaning only 5 phones be
recommended to users not all phones are matched)

I used (while), but this way was incorrect.

Nima

Nima

unread,
Mar 16, 2012, 7:59:16 AM3/16/12
to CLIPSESG
Thanks,
Found the solution.

Thank you again for the great help.

Best regards,
Nima
Reply all
Reply to author
Forward
0 new messages