Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to retract a slot value of a template #13

Closed
srajan3012 opened this issue Dec 28, 2018 · 1 comment
Closed

How to retract a slot value of a template #13

srajan3012 opened this issue Dec 28, 2018 · 1 comment

Comments

@srajan3012
Copy link

srajan3012 commented Dec 28, 2018

;;---KB.clp---;;
(deftemplate fact_template
        (slot slot_1
                (type SYMBOL))
        (slot slot_2
                (type SYMBOL))
)
(assert (fact 1))
(assert (fact_template (slot_1 v1) (slot_2 v2)))
(defrule rule1
  (fact 1)
  =>
  ?p <- (fact_template (slot_1 ?s1)
  ?q <- (fact_template (slot_2 ?s2)
  (py_retract ?p ?q))
# run.py
import clips
clips_env = clips.Environment()
clips_env.load("KB.clp")

def py_retract(p, q):
    env.build('retract '+str(p))

clips_env.define_function(py_retract)
clips_env.run()

This does not works as both p and q are not fact-identifier but come as entire fact-template.
How to change only one slot of the template keeping other intact.

@noxdafox
Copy link
Owner

As I already mention in issue #11, GitHub is not the right place for general questions. For that, please use the official CLIPS forum and stackoverflow. Please limit the usage of GitHub issues for bugs or feature requests which are strictly related to the clipspy Python bindings.

This said, before deep diving into integrating CLIPS into any platform I'd recommend you to first get familiar with the CLIPS language itself. You can refer to its Basic Programming Guide and to help yourself you can either use the CLIPS native console or its Jupyter counterpart.

Once you are familiar with the CLIPS language and its quirks, you can refer to the Advanced Programming Guide to better understand how to integrate it into your software. You will then realize that clipspy is just a thin wrapper of CLIPS C programming interface. You can also refer to clipspy documentation at the following link.

The code you are posting is incorrect. (fact_template (slot_1 ?s1) is broken as the number of parenthesis do not match. (fact_template (slot_1 ?s1)) is not going to do what you think. It's going to call a function fact_template which does not exists and therefore the rule execution will stop.

$ clips
         CLIPS (6.30 3/17/15)
CLIPS> (deftemplate foo)
CLIPS> (foo 1)

[EXPRNPSR3] Missing function declaration for foo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants